2014-09-28 4 views
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() 
+2

Этот код не запускается (отсутствует аргумент при вызове 'Кнопки'). Отправьте фактический код, который вы используете. Также было бы неплохо придерживаться [Руководства по именованию Python] (http://legacy.python.org/dev/peps/pep-0008/). – BartoszKP

+2

Ваш код делает что-то принципиально неправильное, что может вызвать несколько типов нежелательных побочных эффектов. Вы никогда не должны создавать больше одного экземпляра 'Tk'. Если вам нужно несколько окон, вам нужно создать экземпляры «Toplevel». –

ответ

0

Вам действительно нужно пересмотреть свой подход, на мой взгляд, вот так, как я хотел бы сделать то, что вы до сих пор:

from tkinter import * 

#Parent Window Setup 
GoodChefWindow = Tk() 
GoodChefWindow.title("Welcome To GoodChef") 
GoodChefWindow.geometry("600x500") 

#Displaying Company Logo 
Logo=PhotoImage(file="rd.gif") 
LogoCanvas=Canvas(GoodChefWindow,height=150, width=600) 
LogoCanvas.create_image(300,75,image=Logo) 
LogoCanvas.pack() 

#Pickup and Delivery buttons 
def Delivery_Clicked(): 
    Delivery=Toplevel() 
    Delivery.title("Delivery Options") 
    Delivery.geometry("400x333") 
    Remove_Buttons(MenuButtonsFrame) 

def PickUp_Clicked(): 
    Delivery=Toplevel() 
    Delivery.title("Pick Up Options") 
    Delivery.geometry("400x333") 
    Remove_Buttons(MenuButtonsFrame) 

def Remove_Buttons(MenuButtonsFrame): 
    MenuButtonsFrame.destroy() 

DeliveryIcon=PhotoImage(file="rd.gif") 
PickUpIcon=PhotoImage(file="rd.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 = Button(DeliveryLabelFrame,bg="red", 
           fg="yellow",compound="left", 
           image=DeliveryIcon,height=40, 
           width=120,text="Delivery", 
           command=Delivery_Clicked) 
PickUpButton = Button(PickUpLabelFrame,bg="red", 
           fg="yellow",compound="left", 
           image=PickUpIcon,height=40, 
           width=120,text="Pick Up", 
           command=PickUp_Clicked) 
DeliveryButton.pack() 
PickUpButton.pack() 

mainloop() 

Это должно помочь? если не говорить! вы также можете сделать больше tk-окон (toplevel не требуется).

Смежные вопросы