我用Python 2.7和Tkinter编写了一个应用程序。我创建了一个工具栏,其中包含几个按钮,打开相应的顶级窗口显示不同的选项。我使用ttk.Checkbutton,使用“toolbutton”样式来指示选项窗口是打开还是关闭。
问题在于,如果选择另一个窗口,则选项窗口将到后面。目前,如果再次选择工具按钮,则选项窗口将关闭。然而,我只想在选项窗口在顶部时关闭窗口。如果选项窗口没有在顶部,我想让窗口移到前面。
以下是我正在使用的部分代码:
这里是我编写的整个应用程序的图片: 在上面的图片中,每个窗口都有它们各自的ttk.checkbutton。目前,切换checkbutton会打开或关闭窗口。然而,我真正想要的是,如果该窗口在应用程序前面,则将其关闭;如果该窗口在应用程序后面,则将其置于最前面。
希望这能解决一些问题。
提前致谢!
问题在于,如果选择另一个窗口,则选项窗口将到后面。目前,如果再次选择工具按钮,则选项窗口将关闭。然而,我只想在选项窗口在顶部时关闭窗口。如果选项窗口没有在顶部,我想让窗口移到前面。
以下是我正在使用的部分代码:
class MainWindow:
def __init__(self,application):
self.mainframe=tk.Frame(application)
application.geometry("900x600+30+30")
self.otherOptionsSelect=tk.IntVar()
self.otherOptions_Button=ttk.Checkbutton(application,style='Toolbutton',variable=self.otherOptionsSelect,
onvalue=1, offvalue=0,image=self.optionsIcon, command=self.otherOptions)
def otherOptions(self):
if self.otherOptionsSelect.get()==0:
self.otherOptions.destroy()
return
self.otherOptions=tk.Toplevel()
self.otherOptions.title("IsoSurface Options")
self.otherOptions.geometry("200x165+"+str(int(application.winfo_x())+555)+"+"+str(int(application.winfo_y())+230))
self.otherOptApply_button=ttk.Button(self.otherOptions,text="Apply",command=self.showFrame)
self.otherOptApply_button.place(x=20,y=80,width=50,height=30)
self.otherOptClose_button=ttk.Button(self.otherOptions,text="Close",command=self.otherOptionsClose)
self.otherOptClose_button.place(x=80,y=80,width=50,height=30)
def otherOptionsClose(self):
self.otherOptionsSelect.set(0)
self.otherOptions.destroy()
这里是我编写的整个应用程序的图片: 在上面的图片中,每个窗口都有它们各自的ttk.checkbutton。目前,切换checkbutton会打开或关闭窗口。然而,我真正想要的是,如果该窗口在应用程序前面,则将其关闭;如果该窗口在应用程序后面,则将其置于最前面。
希望这能解决一些问题。
提前致谢!