from Tkinter import *
class Window(Tk):
def __init__(self, parent):
Tk.__init__(self, parent)
self.parent = parent
self.initialize()
def initialize(self):
self.geometry("600x400+30+30")
wButton = Button(self, text='text', command = self.OnButtonClick())
wButton.pack()
def OnButtonClick(self):
top = Toplevel()
top.title("title")
top.geometry("300x150+30+30")
topButton = Button(top, text="CLOSE", command = self.destroy)
topButton.pack()
if __name__ == "__main__":
window = Window(None)
window.title("title")
window.mainloop()
# top.lift(aboveThis=self)
#self.configure(state=DISABLED) - unknown option "-state"
#ss = self.state()
#self["state"] = "disabled" - unknown option "-state"
#ws = window.state() # >>> ws outputs: 'normal'
# varname.unbind("<Button-1>", OnButtonClick)
#self.unbind("<Button-1>", OnButtonClick)
#window.unbind("<Button-1>")
###if window.OnButtonClick == True:
### window.unbind("<Button-1>", OnButtonClick)
Python的ver2.7.3代碼如上所述,當在IDLE ver2.7.3跑,使用 Tkver8.5:第一顯示較小的頂部= Toplevel的()窗口對於 秒,在顯示窗口=窗口(Tk)的一個實例之前,它就是 。這是在任何按鈕被點擊或任何東西之前。
上面的代碼下面的所有評論只是我自己的事情,我已經嘗試和想法嘗試下一個(idk - 也許沒有幫助的東西)的筆記。
如何將上面的代碼更改爲:將window = Window(Tk)的實例作爲父窗口,將top = Toplevel()窗口作爲子窗口。然後,當我運行程序時,只有父窗口應該顯示;然後當我點擊'wButton'時,子窗口應該出現在父窗口的頂部,父窗口被禁用 - 它的按鈕不可操作,並且用戶無法通過點擊將窗口提升到最前沿?Python的GUI代碼點擊一個按鈕以打開另一個窗口打破
請驗證顯示代碼的正確性(縮進)。另外,儘量縮短問題的範圍,但要注意點。 –
現在將代碼顯示在上方,就像我在* .py文件中輸入代碼一樣。感謝您修復我的格式錯誤。我猜想一些不正確的縮進之前就搞亂了,因爲當我把帖子放在* .html文件中時,它顯示正確。我會縮小非代碼,問題部分,然後編輯帖子。 –