【发布时间】:2013-12-09 10:32:21
【问题描述】:
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:首先显示较小的 top=Toplevel() 窗口
第二,在显示上面的 window=Window(Tk) 的一个实例之前
它。这是在单击任何按钮或任何内容之前。
上面代码下面的所有 cmets 只是对我自己的笔记,我已经尝试过的事情和接下来要尝试的想法(idk - 也许是无用的东西)。
如何将上述代码更改为:将 window=Window(Tk) 的实例设为父窗口,将 top=Toplevel() 窗口设为子窗口。然后,当我运行程序时,应该只显示父窗口;然后当我点击'wButton'时,子窗口应该出现在父窗口的顶部,父窗口被禁用 - 它的按钮无法操作并且用户无法通过点击它使窗口提升到最前面?
【问题讨论】:
-
请验证显示代码的正确性(缩进)。另外,请尽量让您的问题简短,但要切中要害。
-
代码现在显示在上面,就像我在 *.py 文件中输入的一样。感谢您修复我的格式错误。我猜以前是一些不正确的缩进弄乱了它,因为当我把帖子放在 *.html 文件中时,它显示正确。我将删减非代码、问题部分,然后编辑帖子。
标签: python python-2.7 tkinter