python - 当打开一个新框架然后返回主页时,主页混乱
问题描述
当我登录时一切都很好,它把我带到主页,当我点击查看菜单然后点击后退按钮时,它把我带回到主页,一切都很好,但是当我点击时我想要的方式在订单菜单上,然后按返回按钮返回主页,我的主页一团糟,我看到部分“功能: ”功能,我该如何解决这个问题?
对不起,如果代码有点长,我已经删掉了大部分不必要的代码(或试图)。谢谢您的帮助
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()
解决方案
您必须缩进 Goode Brothers 类下的方法
推荐阅读
- ms-access - MS Access 错误:无法在 Updte 或 Append 查询中添加所有记录 -
- c++ - C++/Java 中的运算符优先级
- javascript - 除了从表单中选择值之外,如何在单击提交按钮时操作模型属性的成员?
- windows - Copy-Item Recursive by *FILE* date modified,但保留文件夹
- reactjs - Antd beforeUpload 对于不同的文件格式不能按预期工作
- swift - TableView NSFetchedResultsController CoreData:错误
- python - 使用 pymongo 加快写入 mongoDB
- php - 是否可以使用域 url 在流明中获取路由参数?
- xcode - react-native 应用程序启动缓慢(ios)
- android - Android Studio 模拟器不工作,立即崩溃