0
我在做一个在学校的编码项目,我试图为我的按钮设置功能 ,但是当我运行代码时按钮运行的命令没有被点击,他们不消失因为按钮隐藏的功能提到他们不工作:使按钮消失在Tkinter
from tkinter import *
import tkinter
#Parent Window Setup
GoodChefWindow = Tk()
GoodChefWindow.title("Welcome To GoodChef")
GoodChefWindow.geometry("600x500")
#Displaying Company Logo
Logo=PhotoImage(file="LogoV2.gif")
LogoCanvas=tkinter.Canvas(GoodChefWindow,height=150, width=600)
LogoCanvas.create_image(300,75,image=Logo)
LogoCanvas.pack()
#Pickup and Delivery buttons
def Delivery_Clicked():
Delivery=Tk()
Delivery.title("Delivery Options")
Delivery.geometry("400x333")
Remove_Buttons()
def PickUp_Clicked():
Delivery=Tk()
Delivery.title("Pick Up Options")
Delivery.geometry("400x333")
Remove_Buttons()
def Remove_Buttons():
MenuButtonsFrame.destroy()
def Buttons(MenuButtonsFrame):
DeliveryIcon=PhotoImage(file="Delivery_Icon.gif")
PickUpIcon=PhotoImage(file="Pick_Up_Icon.gif")
MenuButtonsFrame = LabelFrame(GoodChefWindow, text="Order")
MenuButtonsFrame.pack()
DeliveryLabelFrame = LabelFrame(MenuButtonsFrame)
DeliveryLabelFrame.pack(side=RIGHT,expand="yes")
PickUpLabelFrame = LabelFrame(MenuButtonsFrame)
PickUpLabelFrame.pack(side=LEFT,expand="yes")
DeliveryButton = tkinter.Button(DeliveryLabelFrame,bg="red",
fg="yellow",compound="left",
image=DeliveryIcon,height=40,
width=120,text="Delivery",
command=Delivery_Clicked())
PickUpButton = tkinter.Button(PickUpLabelFrame,bg="red",
fg="yellow",compound="left",
image=PickUpIcon,height=40,
width=120,text="Pick Up",
command=PickUp_Clicked())
DeliveryButton.pack()
PickUpButton.pack()
Buttons()
此代码不运行(在调用'Buttons'时缺少参数)。请发布您正在运行的实际代码。此外,遵守[Python命名指南](http://legacy.python.org/dev/peps/pep-0008/)会很好。 – BartoszKP 2014-09-28 11:21:24
您的代码正在做一些根本性错误的操作,这可能会导致多种类型的不良副作用。你不应该创建超过一个'Tk'的实例。如果你需要多个窗口,你需要创建'Toplevel'实例。 – 2014-09-28 12:57:30