我用tkinter
函數來創建一個新的窗口,它工作正常。
當我從這個窗口鏈接到另一個窗口時,該按鈕移動到第一個窗口。我不明白它爲什麼會移動。爲什麼按鈕移動到當前窗口?
這是第一個窗口中的代碼,
import tkinter
window = tkinter.Tk()
window.title ("Login")
window.geometry ("300x150")
username = "Gurdip"
password = "1234"
def login():
if txtUser.get() == username and txtPass.get() == password:
import NewWindow
lblUser = tkinter.Label(window, text="Username:")
lblUser.pack()
txtUser = tkinter.Entry(window)
txtUser.pack()
lblPass = tkinter.Label(window, text="Password:")
lblPass.pack()
txtPass = tkinter.Entry(window)
txtPass.pack()
btnenter = tkinter.Button(window, text="Enter", command=login)
btnenter.pack()
而對於第二個窗口
import tkinter
window = tkinter.Tk()
window.title ("The Royal Liberty School")
window.geometry ("300x150")
def webpage():
import webbrowser
webbrowser.open("http://www.royalliberty.org.uk/")
lblRlib = tkinter.Label(window, text="Welcome to the Royal Liberty School\n\nClick the link to go to our website")
lblRlib.pack()
def button():
webbutton = tkinter.Button(text ="Royal Liberty School", command = webpage)
webbutton.pack()
button()
你的問題就沒有意義了。按鈕通常不會「移動」。你是說按鈕實際上是從一個窗口移動到另一個窗口?另外,這兩個獨立的tkinter程序,還是將所有這些代碼合併爲一個程序? –