2013-05-01 92 views
0

我在python tkinter中創建了一個雙窗格的窗格。它會打開它自己的罰款,但在一個if語句不再打開Tkinter panedwindow沒有打開

首先,我只是自己的panedwindow的代碼,但我想在另一段代碼中使用它。它不會在if語句中工作,它似乎被忽略。我哪裏錯了?

from tkinter import * 
import time 

ticketCost=6 
username="Rob" 

code = input("Enter code: ") 
if code == "123": 
    year=str(time.localtime()[0]) 
    month=str(time.localtime()[1]) 
    day=str(time.localtime()[2]) 
    hour=str(time.localtime()[3]) 
    minute=str(time.localtime()[4]) 
    ticketTime=str(hour+":"+minute) 
    ticketDate=str(day+"/"+month+"/"+year) 
    ticketInfo="Bus ticket\nSingle\nDate: "+ticketDate+"\nTime: "+ticketTime+"\nPassengers: "+ 
    ...str(int(ticketCost/3))+"\nPrice: "+str(ticketCost)+" credits" 
    ticketWindow = PanedWindow(orient=VERTICAL,bg="white") 
    ticketWindow.pack(fill=BOTH, expand=1) 
    top = Label(ticketWindow, text="top pane") 
    photo = PhotoImage(file='Coach 1.gif') 
    top.config(image=photo,bg="white") 
    top.image = photo 
    ticketWindow.add(top) 
    bottom = Label(ticketWindow, text="bottom pane") 
    bottom.config(text=ticketInfo) 
    bottom.config(bg="white") 
    ticketWindow.add(bottom) 
    print("\nThank you", username) 
else: 
    print("no") 
+1

FWIW - 'year,month,day,hour,minute = map(str,time.localtime()[:5])'我認爲應該可以工作 – mgilson 2013-05-01 12:54:54

+0

我的問題是panedwindow無法打開 – user2339371 2013-05-01 13:09:10

+0

對不起,不要說這會導致你的程序工作。只需清理一下。我假設你確定你在'if'語句中選擇了正確的分支,但事情仍然沒有顯示出來? – mgilson 2013-05-01 13:11:41

回答

0

您似乎沒有創建根窗口,也沒有啓動事件循環。

+0

我對python很新,這是什麼意思? – user2339371 2013-05-01 13:27:14

+0

這意味着你必須首先創建一個'Tk'類的實例,然後你必須調用該實例的'mainloop'方法作爲程序的最後一行。例如:http://www.pythonware.com/library/tkinter/introduction/hello-tkinter.htm – 2013-05-01 13:46:51