开发者

why do I get a blank tkinter window?

so when i run this code and click the button:

from Tkinter import *
import thread
class App:
    def __init__(self, master):
        print master

        def creatnew():

            admin=Tk()
            lab=Label(admin,text='Workes')
            lab.pack()
            admin.minsize(width=250, height=250)
            admin.maxsize(width=250, height=250)
            admin.configure(bg='light green')
            admin.mainloop()
        def 开发者_JS百科other():
            la=Label(master,text='other')
            la.pack()
            bu=Button(master,text='clicks',command=lambda: thread.start_new_thread(creatnew,()))
            bu.pack()
        other()

Admin = Tk()

Admin.minsize(width=650, height=500)
Admin.maxsize(width=650, height=500)
app = App(Admin)
Admin.mainloop()

i get a second tkinter window but its a white blank screen that makes both programs not respond. any ideas


Don't use threads. It's confusing the Tkinter mainloop. For a second window create a Toplevel window.

Your code with minimal modifications:

from Tkinter import *
# import thread # not needed

class App:
    def __init__(self, master):
        print master

        def creatnew(): # recommend making this an instance method

            admin=Toplevel() # changed Tk to Toplevel
            lab=Label(admin,text='Workes')
            lab.pack()
            admin.minsize(width=250, height=250)
            admin.maxsize(width=250, height=250)
            admin.configure(bg='light green')
            # admin.mainloop() # only call mainloop once for the entire app!
        def other(): # you don't need define this as a function
            la=Label(master,text='other')
            la.pack()
            bu=Button(master,text='clicks',command=creatnew) # removed lambda+thread
            bu.pack()
        other() # won't need this if code is not placed in function

Admin = Tk()

Admin.minsize(width=650, height=500)
Admin.maxsize(width=650, height=500)
app = App(Admin)
Admin.mainloop()
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜