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