在python3.4中使用Tkinter时,我遇到了多GUI窗口的问题。我创建了两个GUI窗口。当代码运行时,第一个GUI将出现,第二个将出现在"另一个"点击按钮。但是输入框是空的," 10.10.10.20"应该在其中。我不知道为什么。下面是python代码。有人可以帮助我吗?
from tkinter import *
def kkk():
tt=Tk()
fram2(tt)
class fram1:
def __init__(self,master):
var = IntVar()
menubar=Menu(master)
filemenu = Menu(menubar, tearoff=1)
filemenu.add_command(label='file', command=lambda:print('file'))
menubar.add_cascade(label='file', menu=filemenu)
master.config(menu=menubar)
Label(master, text="First").grid(sticky=E)
Label(master, text="Second").grid(sticky=E)
e1 = Entry(master)
e2 = Entry(master)
e1.grid(row=0, column=1)
e2.grid(row=1, column=1)
checkbutton = Checkbutton(master, text='Preserve aspect', variable=var)
checkbutton.grid(columnspan=2, sticky=W)
button1 = Button(master, text='quit',command=master.destroy)
button1.grid(row=2, column=2)
button2 = Button(master, text='another',command=kkk)
button2.grid(row=2, column=3)
class fram2:
def __init__(self,t):
t.title("IP address")
t.geometry('500x100')
self.frm = Frame(t)
var_char = StringVar()
Entry(self.frm, textvariable=var_char, width = 22, font =('Verdana',13)).pack(side=RIGHT)
var_char.set('10.10.10.20')
Label(self.frm, text = 'IP Address', font =('Arial',12)).pack(side=LEFT)
self.frm.pack(side =LEFT,anchor='nw')
root=Tk()
fram1(root)
mainloop()