gpt4 book ai didi

python - Tkinter 新窗口

转载 作者:行者123 更新时间:2023-11-30 22:08:39 34 4
gpt4 key购买 nike

我对 Tkinter 比较陌生,我需要帮助。

当从父窗口单击按钮时,我创建了一个新窗口。新窗口是 def new_Window。但我似乎无法获取窗口中的信息,如下编码:

from tkinter import *
from tkinter import ttk



#User Interface Code

root = Tk() #Creates the window
root.title("Quiz Game")

def new_window():
newWindow = Toplevel(root)
display = Label(newWindow, width=200, height=50)
message = Label(root, text="Welcome")
display.pack()
message.pack()


display2 = Label(root, width=100, height=30)

button1 = Button(root, text ="Continue", command=new_window, width=16,
bg="red")

message_label = Label(root, text="Click 'Continue' to begin.",
wraplength=250)

username = StringVar() #Stores the username in text
user_entry = Entry(root, textvariable=username) #Creates an entry for the
username
user_entry.pack()
display2.pack()
button1.pack()
message_label.pack()

root.mainloop()#Runs the main window loop

感谢您的帮助。

最佳答案

您没有将 hello 标签打包到新窗口中。还有一个技巧是在开发时使用背景颜色来可视化标签。这是适合您的功能代码。我只更改了 2 行,添加了前景和背景。

from tkinter import *
from tkinter import ttk



# User Interface Code

root = Tk() # Creates the window
root.title("Quiz Game")

def new_window():
newWindow = Toplevel(root)
display = Label(newWindow, width=200, height=50,bg='RED')
message = Label(newWindow, text="HEEEY",fg='BLACK',bg='GREEN')
message.pack()
display.pack()


display2 = Label(root, width=100, height=30)

button1 = Button(root, text ="Continue", command=new_window, width=16,
bg="red")

message_label = Label(root, text="Click 'Continue' to begin.",
wraplength=250)

username = StringVar() # Stores the username in text
user_entry = Entry(root, textvariable=username) # Creates an entry for the
username
user_entry.pack()
display2.pack()
button1.pack()
message_label.pack()

root.mainloop() # Runs the main window loop

关于python - Tkinter 新窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52116301/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com