简体   繁体   English

Tkinter窗格打开

[英]Tkinter panedwindow not opening

I have created a panedwindow in python tkinter with two panes. 我用两个窗格在python tkinter中创建了一个panedwindow。 It will open fine on it's own but within an if statement it no longer opens 它会自行打开,但在if语句中它将不再打开

First I had just the code for the panedwindow on it's own but I wanted to use it within another section of code. 首先,我只有单独的窗格的代码,但是我想在另一部分代码中使用它。 It won't work within an if statement, it appears to be ignored. 它不能在if语句中使用,它似乎被忽略了。 Where have I gone wrong? 我哪里出问题了?

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")

您似乎并没有在创建根窗口,也没有在开始事件循环。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM