我正在使用PyCharm作为IDE学习Python3.x中tinker的基础知识。我正在构建一个基本的两窗口程序,在该程序中,单击欢迎窗口中的CustomerButton后应调用“Customer choice”窗口。 欢迎窗口有两个按钮-客户和员工。 客户选择窗口有两个按钮-订单和取消订单。 出于某种原因,会出现一个空白的“客户选择”窗口,而不是预期的窗口
from tkinter import *
print("aa")
def customerwindow():
root1 = Tk()
root1.title("Customer Choice")
window_width = 1000
window_height = 600
screen_height = root1.winfo_screenheight()
screen_width = root1.winfo_screenwidth()
x_coordinate = (screen_width / 2) - (window_width / 2)
y_coordinate = (screen_height / 2) - (window_height / 2)
root1.geometry('%dx%d+%d+%d' % (window_width, window_height, x_coordinate, y_coordinate))
frame1 = Frame(root1, height=1000, width=600)
frame1.pack(fill=BOTH)
Order = PhotoImage(file="fast-food.png")
Cancel = PhotoImage(file="delete.png")
OrderButton = Button(frame1, image=Order)
OrderButton.place(x=152, y=125)
CancelButton = Button(frame1, image=Cancel)
CancelButton.place(x=550, y=125)
OrderLabel = Label(frame1, text=" ORDER", font=("Poiret One", 24), fg='#34495E')
CancelLabel = Label(frame1, text=" CANCEL ORDER", font=("Poiret One", 24), fg='#34495E')
OrderLabel.place(x=152, y=405)
CancelLabel.place(x=550, y=405)
mainloop()
print("bb")
def welcomeWindow():
root = Tk()
root.title("Welcome")
window_width = 1000
window_height = 600
screen_height = root.winfo_screenheight()
screen_width = root.winfo_screenwidth()
x_coordinate = (screen_width/2) - (window_width/2)
y_coordinate = (screen_height/2) - (window_height/2)
root.geometry('%dx%d+%d+%d' % (window_width, window_height, x_coordinate, y_coordinate))
frame1 = Frame(root, height=1000, width=600)
frame1.pack(fill=BOTH)
customerPhoto = PhotoImage(file="boy.png")
staffPhoto = PhotoImage(file="boss.png")
customerButton = Button(frame1, image=customerPhoto, command=customerwindow)
customerButton.place(x=152, y=125)
staffButton = Button(frame1, image=staffPhoto)
staffButton.place(x=550, y=125)
customerLabel = Label(frame1, text=" CUSTOMER", font=("Poiret One", 24), fg='#34495E')
staffLabel = Label(frame1, text=" STAFF", font=("Poiret One", 24), fg='#34495E')
customerLabel.place(x=152, y=405)
staffLabel.place(x=550, y=405)
mainloop()
welcomeWindow()
print("SS")
#aa,bb,ss are just to check the interpreters progress.
将“root”传递给customerwindow函数,并使用顶层而不是第二个Tk()实例,这可能会导致问题。当您发布无法运行的代码(例如使用图像等)时,不要期望将来有太多帮助
相关问题 更多 >
编程相关推荐