English 中文(简体)
窗户之间自由过渡?
原标题:Tkinter Freely transition between windows?

因此,我不想再从实地重建我的方案。 因此,在我这样做之前,我不会将10个不同的Tk()物体改变为顶级。 我很想知道什么。 我将着重从窗口1向2过渡,并再次回头。

from tkinter import *
Window1 = Tk()
Window2 = Tk()

Window1.title( first window )
Window1.geometry("800x800")

def Window_2():
   Window1.withdraw()
   Window2.title( Second Window )
   Window2.geometry("800x800")
   Button2.pack()
   Window2.mainloop()
....
....

Button1 = Button(Window1, text =  Go to 2 , command = Window_2)
Button2 = Button(Window2, text =  Go to 1 , command = lambda: [Window2.withdraw(), Window1.deiconify()])
Button1.pack()
Window1.mainloop()

我愿在窗户之间自由开一个封闭点和一个开放点。 当我执政时,我可以坐到窗户2上,再回到1个罚款上,而窗口2只是下台的黑板。 任何帮助都会受到高度赞赏。

Edit。 如果你照此办理,我只说删除了两条。

问题回答

您需要打电话<代码>Window2.deiconification(),而不是Window2.mainloop() 载于以显示hidden/em>Window2

正如在评论中所说的那样,最好使用<代码>Toplevel()而不是儿童窗口,并且只需要使用mainloop()。

def Window_2():
   Window1.withdraw()
   Window2.title( Second Window )
   Window2.geometry("800x800")
   Button2.pack()
   Window2.deiconify() # for showing back Window2 if it is hidden
   # don t need to call mainloop() here

Also suggest to call Window2.withdraw() after creating Window2 to make it hidden initially.

下面是一部法典。 你会看到,我正在就使用顶级提出建议。 但我现在再次 st。

from tkinter import *

root = Tk()
root.title( change text )
Label1 = Label(root, text =  Change me )
Label1.pack()

def presto():
    Label1.configure(entry1.get())

def open_sub():
    top1 = Toplevel(root)
    top1.title( Buttons )
    label1 = Label(top1, text =  Type Something )
    entry1 = Entry(top1, width = 20)
    button1 = Button(top1, text = "execute", command = presto)
    button2 = Button(top1, text =  close , command = top1.destroy)
    label1.pack()
    entry1.pack()
    button1.pack()
    button2.pack()

button1 = Button(root, text =  page 2 , command = open_sub)
button1.pack()

root.mainloop()

因此,我知道此事无关,但确实对最初的问题作了回答。 在试图改变标签时,存在新的问题。 我发现错误代码:

Exception in Tkinter callback Traceback (most recent call last): File "/data/user/0/ru.iiec.pydroid3/files/aarch64-linux-android/lib/python3.11/tkinter/init.py", line 1948, in call return self.func(*args) ^^^^^^^^^^^^^^^^ File "/data/user/0/ru.iiec.pydroid3/files/temp_iiec_codefile.py", line 9, in presto Label1.configure(entry1.get()) ^^^^^^ NameError: name entry1 is not defined

而且,我可以把第1号从高级职能中删除,因为那时我才获得。

Traceback (most recent call last): File "/data/user/0/ru.iiec.pydroid3/files/temp_iiec_codefile.py", line 8, in entry1 = Entry(top1, width = 20) ^^^^ NameError: name top1 is not defined

我只字不提显示进展和可能赢得的不相关的问题。 我不想删除原来的问题,因为这表明解决办法,而其他人可能认为它有用。





相关问题
How to make a Tkinter window jump to the front?

How do I get a Tkinter application to jump to the front? Currently, the window appears behind all my other windows and doesn t get focus. Is there some method I should be calling?

How to get the absolute path of a file using tkFileDialog?

I am using: file = tkFileDialog.askopenfile(parent=root, mode= rb , filetypes=[( Subrip Subtitle File , *.srt )], title= Choose a subtitle file ) to get a file object specified by the user. ...

How could I get a Frame with a scrollbar in Tkinter?

I d like to have a Frame, where the user could add as many textfields as needed by the application. The application starts with a textfield, and a button below that textfield. When the user presses ...

How to intercept WM_DELETE_WINDOW on OSX using Tkinter

I m trying to keep a Toplevel window from being closed in OSX by intercepting window manager WM_DELETE_WINDOW event. #!/usr/bin/env python from Tkinter import * def speak(): print "woof" ...

Linking Tcl/Tk to Python 2.5

I have an existing Python 2.4 and it is working properly with tkinter as I tested it using python import _tkinter import Tkinter Tkinter._test() Now, I have installed ...

How to bundle tkinter?

I am distributing an app that uses the Python/C API. I have all standard python modules in python31.zip which is basically an archive of the Lib folder in the python install directory. Here is the ...

How to play sound till the user hits a key?

First thought of implementing this using threads but python doesnt have a way for killing threads. I have read the other topic on killing threads. Is there any proper platform independent way of doing ...