Python 如何为新窗口编写代码
如何为新窗口编写代码?我有一个按钮,可以创建一个新的,但我喜欢为它编码,我不知道如何。我想我必须以任何方式定义新窗口,但我不知道如何做,因为要使用按钮打开新窗口,必须定义窗口本身,但不定义名称 谢谢你的帮助 我已通过以下方式创建按钮及其命令:Python 如何为新窗口编写代码,python,tkinter,new-window,Python,Tkinter,New Window,如何为新窗口编写代码?我有一个按钮,可以创建一个新的,但我喜欢为它编码,我不知道如何。我想我必须以任何方式定义新窗口,但我不知道如何做,因为要使用按钮打开新窗口,必须定义窗口本身,但不定义名称 谢谢你的帮助 我已通过以下方式创建按钮及其命令: from Tkinter import * import Tkinter as tk master = tk.Tk() def create_window(): #Definion und Festlegung neues Fenster to
from Tkinter import *
import Tkinter as tk
master = tk.Tk()
def create_window(): #Definion und Festlegung neues Fenster
toplevel = Toplevel()
toplevel.title('result')
toplevel.geometry('1500x1000')
toplevel.focus_set()
Button(master, text='forward', command=create_window).pack(padx=5, anchor=N, pady=4)
master.mainloop()
新窗口的编码(或在新窗口中创建小部件)与在主窗口中的编码类似。只需将新窗口(toplevel
)作为父窗口传递即可
下面是一个在新窗口中创建标签
和条目
小部件的示例
from Tkinter import *
import Tkinter as tk
master = tk.Tk() # Create the main window
def create_window(): #Definion und Festlegung neues Fenster
toplevel = Toplevel()
toplevel.title('result')
toplevel.geometry('1500x1000')
# Create widges in the new window
label = tk.Label(toplevel, text="A Label", fg='blue')
entry = tk.Entry(toplevel)
label.pack()
entry.pack()
toplevel.focus_set()
Button(master, text='forward', command=create_window).pack(padx=5, anchor=N, pady=4)
master.mainloop()
不,我想那不是我想要的。对不起,我忘记抄这行了。我想要的是。。。嗯,只需为新窗口编写代码。例如,在新窗口中创建一条闪烁的消息。但是谢谢你我已经更新了答案,以便在新窗口中创建小部件。让我知道你是否正在寻找。你的代码看起来好像已经在创建一个新窗口。你想要的和你已经拥有的有什么不同?