object has no attribute 'tk' - tkinter - python

in the following code is an issue, which I can't find.
The Error:
AttributeError: 'game' object has no attribute 'tk'
I guess it's because the field-function.
The functions, which are important for my program are shown in the following code.
import tkinter as tkinter
from tkinter import *
# class for the game
class game(tkinter.Frame):
def __init__(self):
# main-window
self.root = tkinter.Tk()
# title
self.root.title("TicTacToe")
# text member
self.text = tkinter.StringVar()
self.text.set(" ")
# config
self.root.geometry("178x130")
self.root.resizable(width=0, height=0)
self.root['bg'] = '#1c6796'
self.root.iconphoto(True, tkinter.PhotoImage(file=r'C:\Users\nicod\Desktop\TicTacToe\icon.png'))
# buttons
self.singleplayer_button = Button(self.root, text = "Singleplayer", command = self.singleplayer_window, font = 'Times 10 italic')
self.multiplayer_button = Button(self.root, text = "Multiplayer", command = self.multiplayer_window, font = 'Times 10 italic')
self.quit_button = Button(self.root, text = "Quit", command = quit, font = 'Times 10 italic')
self.singleplayer_button.place(x = 48, y = 10)
self.multiplayer_button.place(x = 51, y = 50)
self.quit_button.place(x = 70, y = 90)
self.root.mainloop()
def quit(self):
self.root.destroy()
def field(self):
# 9 buttons for the field
self.field1 = tkinter.Button(self, textvariable=self.text, command = self.move, height = 2, width = 4)
self.field2 = tkinter.Button(self, textvariable=self.text, command = self.move, height = 2, width = 4)
self.field3 = tkinter.Button(self, textvariable=self.text, command = self.move, height = 2, width = 4)
self.field4 = tkinter.Button(self, textvariable=self.text, command = self.move, height = 2, width = 4)
self.field5 = tkinter.Button(self, textvariable=self.text, command = self.move, height = 2, width = 4)
self.field6 = tkinter.Button(self, textvariable=self.text, command = self.move, height = 2, width = 4)
self.field7 = tkinter.Button(self, textvariable=self.text, command = self.move, height = 2, width = 4)
self.field8 = tkinter.Button(self, textvariable=self.text, command = self.move, height = 2, width = 4)
self.field9 = tkinter.Button(self, textvariable=self.text, command = self.move, height = 2, width = 4)
self.back = tkinter.Button(self, text = 'back', command = quit, font = 'Times 10 italic')
# display buttons
self.field1.place(x = 50, y = 10)
self.field2.place(x = 100, y = 10)
self.field3.place(x = 150, y =10)
self.field4.place(x = 50, y = 60)
self.field5.place(x = 100, y = 60)
self.field6.place(x = 150, y = 60)
self.field7.place(x = 50, y = 120)
self.field8.place(x = 100, y = 120)
self.field9.place(x = 150, y = 120)
self.back.place (x = 50, y = 180)
self.reset.place (x = 150, y = 180)
def singleplayer_window(self):
self.sw = tkinter.Toplevel()
self.sw.title("Singleplayer")
# config
self.sw.geometry("240x210")
self.sw.resizable(width=0, height=0)
self.sw.iconphoto(True, tkinter.PhotoImage(file=r'C:\Users\nicod\Desktop\TicTacToe\icon.png'))
# draw the field
self.field()
self.sw.mainloop()
I hope you can help me!
PS: I let out the Multiplayer-function, because it's similar to the singleplayer-funtion.
btw: It was the first time I really worked with classes, so please don't blame me!

You never initialise tkinter.Frame using super().__init__(self.root)
Look at this:
import tkinter as tkinter
from tkinter import *
# class for the game
class Game(tkinter.Frame):
def __init__(self):
# main-window
self.root = tkinter.Tk()
# title
self.root.title("TicTacToe")
# text member
self.text = tkinter.StringVar()
self.text.set(" ")
# config
self.root.geometry("178x130")
self.root.resizable(width=0, height=0)
self.root['bg'] = '#1c6796'
self.root.iconphoto(True, tkinter.PhotoImage(file=r'C:\Users\nicod\Desktop\TicTacToe\icon.png'))
# buttons
self.singleplayer_button = Button(self.root, text = "Singleplayer", command = self.singleplayer_window, font = 'Times 10 italic')
self.multiplayer_button = Button(self.root, text = "Multiplayer", command = self.multiplayer_window, font = 'Times 10 italic')
self.quit_button = Button(self.root, text = "Quit", command = quit, font = 'Times 10 italic')
self.singleplayer_button.place(x = 48, y = 10)
self.multiplayer_button.place(x = 51, y = 50)
self.quit_button.place(x = 70, y = 90)
self.root.mainloop()
def quit(self):
self.root.destroy()
def field(self):
# 9 buttons for the field
self.field1 = tkinter.Button(self, textvariable=self.text, command = self.move, height = 2, width = 4)
self.field2 = tkinter.Button(self, textvariable=self.text, command = self.move, height = 2, width = 4)
self.field3 = tkinter.Button(self, textvariable=self.text, command = self.move, height = 2, width = 4)
self.field4 = tkinter.Button(self, textvariable=self.text, command = self.move, height = 2, width = 4)
self.field5 = tkinter.Button(self, textvariable=self.text, command = self.move, height = 2, width = 4)
self.field6 = tkinter.Button(self, textvariable=self.text, command = self.move, height = 2, width = 4)
self.field7 = tkinter.Button(self, textvariable=self.text, command = self.move, height = 2, width = 4)
self.field8 = tkinter.Button(self, textvariable=self.text, command = self.move, height = 2, width = 4)
self.field9 = tkinter.Button(self, textvariable=self.text, command = self.move, height = 2, width = 4)
self.back = tkinter.Button(self, text = 'back', command = quit, font = 'Times 10 italic')
# display buttons
self.field1.place(x = 50, y = 10)
self.field2.place(x = 100, y = 10)
self.field3.place(x = 150, y =10)
self.field4.place(x = 50, y = 60)
self.field5.place(x = 100, y = 60)
self.field6.place(x = 150, y = 60)
self.field7.place(x = 50, y = 120)
self.field8.place(x = 100, y = 120)
self.field9.place(x = 150, y = 120)
self.back.place (x = 50, y = 180)
self.reset.place (x = 150, y = 180)
def singleplayer_window(self):
self.sw = tkinter.Toplevel()
self.sw.title("Singleplayer")
super().__init__(self.sw) # Initialise the frame
super().pack() # `pack`/`grid`/`place` the frame
# config
self.sw.geometry("240x210")
self.sw.resizable(width=0, height=0)
self.sw.iconphoto(True, tkinter.PhotoImage(file=r'C:\Users\nicod\Desktop\TicTacToe\icon.png'))
# draw the field
self.field()
self.sw.mainloop()
app = Game()
That will cause problems if you call singleplayer_window multiple times as # BryanOakley said. That is why I think you shouldn't inherit from tkinter.Frame so:
import tkinter as tkinter
from tkinter import *
# class for the game
class Game:
def __init__(self):
# main-window
self.root = tkinter.Tk()
# title
self.root.title("TicTacToe")
# text member
self.text = tkinter.StringVar()
self.text.set(" ")
# config
self.root.geometry("178x130")
self.root.resizable(width=0, height=0)
self.root['bg'] = '#1c6796'
self.root.iconphoto(True, tkinter.PhotoImage(file=r'C:\Users\nicod\Desktop\TicTacToe\icon.png'))
# buttons
self.singleplayer_button = Button(self.root, text = "Singleplayer", command = self.singleplayer_window, font = 'Times 10 italic')
self.multiplayer_button = Button(self.root, text = "Multiplayer", command = self.multiplayer_window, font = 'Times 10 italic')
self.quit_button = Button(self.root, text = "Quit", command = quit, font = 'Times 10 italic')
self.singleplayer_button.place(x = 48, y = 10)
self.multiplayer_button.place(x = 51, y = 50)
self.quit_button.place(x = 70, y = 90)
self.root.mainloop()
def quit(self):
self.root.destroy()
def field(self):
# 9 buttons for the field
self.field1 = tkinter.Button(self.frame, textvariable=self.text, command = self.move, height = 2, width = 4)
self.field2 = tkinter.Button(self.frame, textvariable=self.text, command = self.move, height = 2, width = 4)
self.field3 = tkinter.Button(self.frame, textvariable=self.text, command = self.move, height = 2, width = 4)
self.field4 = tkinter.Button(self.frame, textvariable=self.text, command = self.move, height = 2, width = 4)
self.field5 = tkinter.Button(self.frame, textvariable=self.text, command = self.move, height = 2, width = 4)
self.field6 = tkinter.Button(self.frame, textvariable=self.text, command = self.move, height = 2, width = 4)
self.field7 = tkinter.Button(self.frame, textvariable=self.text, command = self.move, height = 2, width = 4)
self.field8 = tkinter.Button(self.frame, textvariable=self.text, command = self.move, height = 2, width = 4)
self.field9 = tkinter.Button(self.frame, textvariable=self.text, command = self.move, height = 2, width = 4)
self.back = tkinter.Button(self.frame, text = 'back', command = quit, font = 'Times 10 italic')
# display buttons
self.field1.place(x = 50, y = 10)
self.field2.place(x = 100, y = 10)
self.field3.place(x = 150, y =10)
self.field4.place(x = 50, y = 60)
self.field5.place(x = 100, y = 60)
self.field6.place(x = 150, y = 60)
self.field7.place(x = 50, y = 120)
self.field8.place(x = 100, y = 120)
self.field9.place(x = 150, y = 120)
self.back.place (x = 50, y = 180)
self.reset.place (x = 150, y = 180)
def singleplayer_window(self):
self.sw = tkinter.Toplevel()
self.sw.title("Singleplayer")
self.frame = tkinter.Frame(self.sw) # Initialise the frame
self.frame.pack() # `pack`/`grid`/`place` the frame
# config
self.sw.geometry("240x210")
self.sw.resizable(width=0, height=0)
self.sw.iconphoto(True, tkinter.PhotoImage(file=r'C:\Users\nicod\Desktop\TicTacToe\icon.png'))
# draw the field
self.field()
self.sw.mainloop()
app = Game()

You should add self.tk = some_value in your class, because there is really no attribute tk. Or maybe you meant self.root

Related

Empty window while running UI converted python code from Figma

To test Figma for the first time, I created a simple frame with two rectangles and renamed each to "TextBox" while using Figma. After that as per procedure i converted that to a python code and tried running it but it shows an empty window and no rectangles or text boxes. Any clues why is this happening. Here is the code i am running.
from tkinter import *
def btn_clicked():
print("Button Clicked")
window = Tk()
window.geometry("907x645")
window.configure(bg = "#ee1212")
canvas = Canvas(
window,
bg = "#ee1212",
height = 645,
width = 907,
bd = 0,
highlightthickness = 0,
relief = "ridge")
canvas.place(x = 0, y = 0)
entry0_img = PhotoImage(file = f"img_textBox0.png")
entry0_bg = canvas.create_image(
-188.0, 85.5,
image = entry0_img)
entry0 = Entry(
bd = 0,
bg = "#d9d9d9",
highlightthickness = 0)
entry0.place(
x = -338.0, y = 68,
width = 300.0,
height = 33)
entry1_img = PhotoImage(file = f"img_textBox1.png")
entry1_bg = canvas.create_image(
-188.0, 153.5,
image = entry1_img)
entry1 = Entry(
bd = 0,
bg = "#d9d9d9",
highlightthickness = 0)
entry1.place(
x = -338.0, y = 136,
width = 300.0,
height = 33)
background_img = PhotoImage(file = f"Background.png")
background = canvas.create_image(
-266.5, 20.5,
image=background_img)
window.resizable(False, False)
window.mainloop()
Float cannot be used for coordination.
entry0.place(
x = 33, y = 68,
width = 300,
height = 33)
and :
entry1.place(
x = 33, y = 136,
width = 300,
height = 33)

How to get the status of button in tkinter?

from tkinter import *
import time
def checkTime():
if len(hourInput.get()) != 0 and len(minuteInput.get()) != 0 and len(secondInput.get()) != 0:
if hourInput.get() == time.strftime("%H"):
print("good")
window.after(500, checkTime)
def pressButton(button):
button.config(relief=SUNKEN)
if __name__=='__main__':
window = Tk()
window.geometry("1920x1080")
canvas = Canvas(window, width = 1980, height = 1020)
canvas.pack()
hourInput = StringVar()
minuteInput = StringVar()
secondInput = StringVar()
setHour = Entry(window, text = hourInput, font = (20))
setHour.place(x = 100, y = 20, width = 100, height = 40)
setMinute = Entry(window, text = minuteInput, font = (20))
setMinute.place(x = 300, y = 20, width = 100, height = 40)
setSecond = Entry(window, text = secondInput, font = (20))
setSecond.place(x = 500, y = 20, width = 100, height = 40)
canvas.create_text(60, 40, text = "Hour: ", font = (20))
canvas.create_text(260, 40, text = "Minute: ", font = (20))
canvas.create_text(460, 40, text = "Second: ", font = (20))
submit = Button(text = "Submit", height = 2, width = 10, font = (10))
submit.config(command = lambda submit=submit:pressButton(submit))
submit.place(x = 100, y = 100)
checkTime()
window.mainloop()
I want the function checkTime() to be called when my button is pressed. But how to get the status of my button and compare it ? I want to use the function only if the button is pressed as a test that the user agree with his inputs
You can modify the button declaration as follows so that the checkTime() will trigger when the button is pressed.
submit = Button(text = "Submit", height = 2, width = 10, font = (10), relief=SUNKEN)
submit['command'] = checkTime # no parentheses here
Also make sure that the checkTime() method call in the bottom is removed
I put the function checkTime() inside the pressButton() function, and now the program works fine.
from tkinter import *
import time
def checkTime():
if len(hourInput.get()) != 0 and len(minuteInput.get()) != 0 and len(secondInput.get()) != 0:
if hourInput.get() == time.strftime("%H"):
print("good")
window.after(500, checkTime)
def pressButton(button):
button.config(relief = SUNKEN)
checkTime()
if __name__== '__main__':
window = Tk()
window.geometry("1920x1080")
canvas = Canvas(window, width = 1980, height = 1020)
canvas.pack()
hourInput = StringVar()
minuteInput = StringVar()
secondInput = StringVar()
setHour = Entry(window, text = hourInput, font = (20))
setHour.place(x = 100, y = 20, width = 100, height = 40)
setMinute = Entry(window, text = minuteInput, font = (20))
setMinute.place(x = 300, y = 20, width = 100, height = 40)
setSecond = Entry(window, text = secondInput, font = (20))
setSecond.place(x = 500, y = 20, width = 100, height = 40)
canvas.create_text(60, 40, text = "Hour: ", font = (20))
canvas.create_text(260, 40, text = "Minute: ", font = (20))
canvas.create_text(460, 40, text = "Second: ", font = (20))
submit = Button(text = "Submit", height = 2, width = 10, font = (10))
submit.config(command = lambda submit=submit:pressButton(submit))
submit.place(x = 100, y = 100)
window.mainloop()

Can't modify global variable in python

from tkinter import *
import time
check = False
window = Tk()
window.geometry("1920x1080")
def typeTime():
hour = int(time.strftime("%H"))
minute = int(time.strftime("%M"))
second = int(time.strftime("%S"))
hourInput2 = int(hourInput.get())
minuteInput2 = int(minuteInput.get())
secondInput2 = int(secondInput.get())
if(hour == hourInput2 and minute == minuteInput2 and second == secondInput2):
print("now")
global check
check = True
canvas = Canvas(window, width = 1980, height = 1020)
canvas.pack()
hourInput = StringVar()
minuteInput = StringVar()
secondInput = StringVar()
setHour = Entry(window, text = hourInput, font = (20)).place(x = 100, y = 20, width = 100, height = 40)
setMinute = Entry(window, text = minuteInput, font = (20)).place(x = 300, y = 20, width = 100, height = 40)
setSecond = Entry(window, text = secondInput, font = (20)).place(x = 500, y = 20, width = 100, height = 40)
canvas.create_text(60, 40, text = "Hour: ", font = (20))
canvas.create_text(260, 40, text = "Minute: ", font = (20))
canvas.create_text(460, 40, text = "Second: ", font = (20))
submit = Button(text = "Submit", height = 2, width = 10, font = (10), command = typeTime)
submit.place(x = 100, y = 100)
if check == True:
print("Pressed")
submit.config(relief = SUNKEN)
window.mainloop()
I'm trying to make a button to stay pressed, so I tried to make this happens with a global variable. The variable check is initially False, but when typeTime() is called via the submit object it should change its value in True and when check will be tested later to keep my button pressed using config method.
What am I doing wrong, as neither the button is still pressed nor the message "Pressed" is displayed in the console ?
The window.mainloop() is the internal loop inside object window, not in your script so that is why it didn't work. You need to add the action inside the function typeTime:
from tkinter import *
import time
if __name__=='__main__':
check = False
window = Tk()
window.geometry("1920x1080")
def typeTime(button):
hour = int(time.strftime("%H"))
minute = int(time.strftime("%M"))
second = int(time.strftime("%S"))
hourInput2 = int(hourInput.get())
minuteInput2 = int(minuteInput.get())
secondInput2 = int(secondInput.get())
if(hour == hourInput2 and minute == minuteInput2 and second == secondInput2):
print("now")
# global check
# check = True
print('Pressed')
button.config(relief=SUNKEN)
canvas = Canvas(window, width = 1980, height = 1020)
canvas.pack()
hourInput = StringVar()
minuteInput = StringVar()
secondInput = StringVar()
setHour = Entry(window, text = hourInput, font = (20)).place(x = 100, y = 20, width = 100, height = 40)
setMinute = Entry(window, text = minuteInput, font = (20)).place(x = 300, y = 20, width = 100, height = 40)
setSecond = Entry(window, text = secondInput, font = (20)).place(x = 500, y = 20, width = 100, height = 40)
canvas.create_text(60, 40, text = "Hour: ", font = (20))
canvas.create_text(260, 40, text = "Minute: ", font = (20))
canvas.create_text(460, 40, text = "Second: ", font = (20))
submit = Button(text = "Submit", height = 2, width = 10, font = (10))
submit.config(command = lambda submit=submit:typeTime(submit))
submit.place(x = 100, y = 100)
# if check == True:
# print("Pressed")
# submit.config(relief = SUNKEN)
window.mainloop()

Variable not defined in subroutine after defined and made global

The following code gets an error as it says name 'Combo_Box Value' is not defined.
from tkinter import *
from tkinter.ttk import Progressbar
from tkinter.ttk import Combobox
from tkinter.ttk import Notebook
import tkinter.font
class Pounds_Converter():
def __init__(self, parent):
self.gui(parent)
def gui(self, parent):
if parent == 0:
self.w1 = Tk()
self.w1.configure(bg = '#e4f3ff')
self.w1.geometry('370x350')
else:
self.w1 = Frame(parent)
self.w1.configure(bg = '#e4f3ff')
self.w1.place(x = 0, y = 0, width = 370, height = 350)
self.label3 = Label(self.w1, text = "Pounds Converter", bg = "#e4f3ff", fg = "#002d5e", font = tkinter.font.Font(family = "Myanmar Text", size = 24), cursor = "arrow", state = "normal")
self.label3.place(x = 55, y = 50, width = 260, height = 62)
self.label4 = Label(self.w1, text = "Pounds", bg = "#e4f3ff", fg = "#006fe8", font = tkinter.font.Font(family = "Myanmar Text", size = 12), cursor = "arrow", state = "normal")
self.label4.place(x = 60, y = 135, width = 60, height = 22)
self.combo1 = Combobox(self.w1, font = tkinter.font.Font(family = "Myanmar Text", size = 12), cursor = "arrow", state = "normal")
self.combo1.place(x = 250, y = 135, width = 76, height = 22)
self.combo1['values'] = ("Dollars", "Euros")
self.combo1.current(0)
self.combo1.bind("<<ComboboxSelected>>", self.Combo_Box)
self.ltext3 = Entry(self.w1, bg = "#efffff", font = tkinter.font.Font(family = "MS Shell Dlg 2", size = 8), cursor = "arrow", state = "normal")
self.ltext3.place(x = 20, y = 170, width = 140, height = 32)
self.ltext3.insert(INSERT, "0.00")
self.ltext4 = Entry(self.w1, bg = "#efffff", font = tkinter.font.Font(family = "MS Shell Dlg 2", size = 8), cursor = "arrow", state = "normal")
self.ltext4.place(x = 220, y = 170, width = 140, height = 32)
self.button2 = Button(self.w1, text = "Convert", bg = "#efffff", fg = "#006fe8", font = tkinter.font.Font(family = "MS Shell Dlg 2", size = 8), cursor = "arrow", state = "normal")
self.button2.place(x = 120, y = 270, width = 130, height = 30)
self.button2['command'] = self.Convert
self.button3 = Button(self.w1, text = "Home", bg = "#e4f3ff", fg = "#006fe8", font = tkinter.font.Font(family = "Myanmar Text", size = 8), cursor = "arrow", state = "normal")
self.button3.place(x = 20, y = 20, width = 40, height = 16)
def Combo_Box(self, e):
Combo_Box_Value=self.combo1.get()
return Combo_Box_Value
def Convert(self):
global Combo_Box_Value
Pounds=self.ltext3.get()
Pounds = float(Pounds)
if Combo_Box_Value== "Dollars":
Dollars=Pounds*1.38
self.ltext4.delete("0",END)
self.ltext4.insert(INSERT,Dollars)
a = Pounds_Converter(0)
a.w1.mainloop()
That is the full code for that GUI widget. I would like to get the value of the combo box once it is changed then I need to use it in another variable.

when opened a new frame and then going back to the home page, the home page messes up

when I sign in everything is fine and it takes me to the home page, when I click on view menu and then click the back button it takes me back to the home page, everything is still fine and the way I want however when I click on order menu and then press the back button to go back to the home page, my home page messes up and I see parts of "function:" function, how can i fix this?
I'm sorry if the code is a bit long I already cut out most of the unnecessary code (or tried to). Thank you for your help
from tkinter import*
from PIL import Image, ImageTk
import tkinter as tk
root = Tk()
root.geometry('670x466')
accounts = []
food = ['Pizza','Burger','Nachos', 'French Toast']
foodprice=['20','9.50','7.50', '17']
drinks = ['Pepsi','Lemonade','Tea', 'Aperitivo Spritz']
drinksprice = ['3','4','3', '15.50']
class Goode_brothers:
def __init__(self, parent):
self.myFrame = Frame(parent)
self.myFrame.pack()
self.load = Image.open('new-dip-project\\food.jpg')
self.render = ImageTk.PhotoImage(self.load)
self.img = Label(parent, image = self.render)
self.img.place(x = -26, y =0)
self.img_login = PhotoImage(file = 'new-dip-project\\button (3).png')
self.b1 = Button(parent,image = self.img_login, command = self.read_info, bd = 0, bg = '#3b353b', activebackground = '#3b353b')
self.b1.place(x = 275, y = 340)
self.img_register = PhotoImage(file = 'new-dip-project\\register.png')
self.b2 = Button(parent,image = self.img_register, command = self.openNewWindow, bd = 0, bg = '#3b353b', activebackground = '#3b353b')
self.b2.place(x = 265, y = 400)
self.canvas = Canvas(parent, width = 400, height = 120)
self.canvas.pack()
self.img4 = ImageTk.PhotoImage(Image.open('new-dip-project\\goode.png'))
self.canvas.create_image(20, 20, anchor=NW, image=self.img4)
self.email = Entry(parent)
self.email.place(x = 340, y = 180)
self.password = Entry(parent)
self.password.place(x = 354, y = 250)
self.img_label = PhotoImage(file = 'new-dip-project\\label-image.png')
self.name = Label(parent, image = self.img_label, text = "Email:", bg = '#3c3a3b').place(x = 197,y = 178)
self.img_label_pass = PhotoImage(file = 'new-dip-project\\label_pass.png')
self.name = Label(parent, image = self.img_label_pass, text = "Password:", bg = '#3c3a3b').place(x = 177,y = 245)
def openMenu(self):
for wid in root.winfo_children():
wid.destroy()
self.myFrame.destroy()
self.myFrame2 = Frame(root, bg = '')
self.myFrame2.pack(fill = "both", expand = 1)
self.img77 = PhotoImage(file = 'new-dip-project\\goode.png')
self.name77 = Label(self.myFrame2, image = self.img77).pack()
self.img_menu = PhotoImage(file = 'new-dip-project\\menu_button.png')
self.b6 = Button(self.myFrame2,image = self.img_menu, command = self.view_menu, bd = 0)
self.b6.place(x = 246, y = 140)
self.img_order = PhotoImage(file = 'new-dip-project\\order_button.png')
self.b7 = Button(self.myFrame2,image = self.img_order, command = self.order_menu, bd = 0)
self.b7.place(x = 239, y = 228)
self.img_checkout = PhotoImage(file = 'new-dip-project\\checkout.png')
self.b8 = Button(self.myFrame2,image = self.img_checkout, bd = 0)
self.b8.place(x = 250, y = 316)
def view_menu(self):
self.myFrame2.destroy()
self.myFrame3 = LabelFrame(root, height = 700)
self.myFrame3.pack()
self.myFrame3.columnconfigure(0, weight=1)
self.myFrame3.columnconfigure(1, weight=2)
self.food_title = Label(self.myFrame3, font=("Impact", "23"), text = 'Food').grid(row = 0, column = 4)
self.food_space = Label(self.myFrame3, text = '').grid(row = 1, column = 4)
self.drinks_title = Label(self.myFrame3, font=("Impact", "23"), text = 'Drinks').grid(row = 8, column = 4)
self.price = Label(self.myFrame3, font=("Impact", "23"), text = 'Price($)').grid(row = 0, column = 8)
for x in range (len(food)):
self.foodop = Label(self.myFrame3, font=("Impact", "15"), text = food[x]).grid(row = 3+x, column = 4) #A created label defining where it is positioned
self.fprice = Label(self.myFrame3, font=("Impact", "15"), text = foodprice[x]).grid(row = 3+x, column = 8)
for x in range (len(drinks)):
self.drinksop = Label(self.myFrame3, font=("Impact", "15"), text = drinks[x]).grid(row = 5+(len(food))+x, column = 4)
self.drinksp = Label(self.myFrame3, font=("Impact", "15"), text = drinksprice[x]).grid(row = 5+(len(food))+x, column = 8)
self.img_back = PhotoImage(file = 'new-dip-project\\back_button.png')
self.b10 = Button(self.myFrame3,image = self.img_back, command = self.openMenu, bd = 0)
self.b10.grid(row = 38, column = 7)
def order_menu(self):
for wid2 in root.winfo_children():
wid2.destroy()
self.myFrame2.destroy()
self.myFrame4 = Frame(root)
self.myFrame4.pack(fill = "both", expand = 1)
self.tkvar = StringVar(self.myFrame4)
self.tkvar.set("Food")
self.tkvar2 = StringVar(self.myFrame4)
self.tkvar2.set("Drinks")
self.img_odmenu = PhotoImage(file = 'new-dip-project\\od_menu.png')
self.order_menu_message = Label(self.myFrame4, image = self.img_odmenu).place(x = 220)
self.foodMenu = OptionMenu(self.myFrame4, self.tkvar, *food)
self.foodMenu.place(x = 160, y = 110)
self.Foodlabel = Label(self.myFrame4, text="Choose Your Food", font=("Courier New","12"))
self.Foodlabel.place(x = 145, y = 83)
self.drinklabel = Label(self.myFrame4, text="Choose Your Drink", font=("Courier New","12"))
self.drinklabel.place(x = 370, y = 83)
self.drinkMenu = OptionMenu(self.myFrame4, self.tkvar2, *drinks)
self.drinkMenu.place(x = 385, y = 110)
self.pricelabel = Label(self.myFrame4, text = "Total price", font=("Courier New","12"))
self.pricelabel.place(x = 289, y = 208)
self.order_btn78 = PhotoImage(file = 'new-dip-project\\orderb.png')
self.order_btn = Button(self.myFrame4, image = self.order_btn78, bd = 0)
self.order_btn.place(x = 302, y = 160)
self.check_btn = PhotoImage(file = 'new-dip-project\\checkpay.png')
self.checkout_btn = Button(self.myFrame4, image = self.check_btn, bd = 0)
self.checkout_btn.place(x = 267, y = 410)
self.img_odmenu = PhotoImage(file = 'new-dip-project\\od_menu.png')
self.order_menu_message = Label(self.myFrame4, image = self.img_odmenu).place(x = 220)
self.foodMenu = OptionMenu(self.myFrame4, self.tkvar, *food)
self.foodMenu.place(x = 160, y = 110)
self.Foodlabel = Label(self.myFrame4, text="Choose Your Food", font=("Courier New","12"))
self.Foodlabel.place(x = 145, y = 83)
self.drinklabel = Label(self.myFrame4, text="Choose Your Drink", font=("Courier New","12"))
self.drinklabel.place(x = 370, y = 83)
self.drinkMenu = OptionMenu(self.myFrame4, self.tkvar2, *drinks)
self.drinkMenu.place(x = 385, y = 110)
self.pricelabel = Label(self.myFrame4, text = "Total price", font=("Courier New","12"))
self.pricelabel.place(x = 289, y = 208)
self.order_btn78 = PhotoImage(file = 'new-dip-project\\orderb.png')
self.order_btn = Button(self.myFrame4, image = self.order_btn78, bd = 0)
self.order_btn.place(x = 302, y = 160)
self.check_btn = PhotoImage(file = 'new-dip-project\\checkpay.png')
self.checkout_btn = Button(self.myFrame4, image = self.check_btn, bd = 0)
self.checkout_btn.place(x = 267, y = 410)
self.back_menu = PhotoImage(file = 'new-dip-project\\bbutton.png')
self.back_button2 = Button(self.myFrame4, image = self.back_menu, command = self.openMenu, bd = 0)
self.back_button2.place(x = 30, y = 410)
if __name__ == "__main__":
e = Goode_brothers(root)
root.title('Goode brothers')
root.mainloop()
You have to indent the methods under the class Goode Brothers

Categories

Resources