我意识到第一个建议是“停止使用Tix”,但我喜欢一些小部件,即使它们自08年以来一直没有维护。我注意到的一件事是一些对话框不会保持打开状态。例如,我在笔记本小部件内部的LabelFrame Widget中使用了FileEntry Widget。文件对话框如下所示。
当您点击文件对话框按钮时,您会得到:
红色箭头显示该过滤器中的文件下拉菜单,但单击它时没有任何反应。您可以看到一个简短的闪存(就像在几毫秒内),就像检查了一个事件循环或者其他什么东西。与FileEntry上的其他按钮相同。
有关此内容的完整代码,您可以看到here
我认为相关部分是:
import os, os.path, sys, Tix
from Tkconstants import *
import tkFileDialog
import traceback, tkMessageBox
from Tkinter import *
class pyigblast_gui():
def __init__(self,root):
#Initialization
self.root = root
self.exit = -1
self.dir = None
self.argument_dict = {'query':''}
#local
_program_name = sys.argv[0]
_directory_name = os.path.dirname(_program_name)
def MainMenu(self):
main_menu = Tix.Frame(self.root,bd=2,relief=RAISED)
return main_menu
def TabNotebook(self):
notebook_frame = self.root
notebook = Tix.NoteBook(notebook_frame, ipadx=5, ipady=5, bg='black')
notebook.add('f_and_d', label="Files and Databases", underline=0,
createcmd=lambda self=self,nb=notebook,name='f_and_d': self.files_and_directories(nb,name))
notebook.add('readme', label="Usage", underline=0,
createcmd=lambda self=self,nb=notebook,name='readme': self.readme(nb,name) )
return notebook
def files_and_directories(self,nb,name):
f_and_d_page = nb.page(name)
options = "label.padX4"
self.input_frame = Tix.LabelFrame(f_and_d_page,options=options)
self.input_frame.pack(side=TOP,expand=0,fill=BOTH)
self.make_fasta_entry()
#self.input_frame.grid(in_=f_and_d_page,row=0,column=0,columnspan=2)
def make_fasta_entry(self):
message = Tix.Message(self.input_frame,relief=Tix.FLAT, width=500, anchor=W,
text='Enter the entry FASTA file here',font=('Arial',16))
self.fasta_entry = Tix.FileEntry(self.input_frame, label="Select a FASTA file:",selectmode="normal")
message.pack(side=TOP,expand=1,fill=BOTH,padx=3,pady=3)
self.fasta_entry.pack(side=TOP,fill=X,padx=3,pady=3)
def build(self):
window_info = self.root.winfo_toplevel()
window_info.wm_title('PyIgBLAST - GUI')
#if window_info <= 800:
window_info.geometry('1500x900+10+10')
frame1 = self.MainMenu()
frame1.pack(side=BOTTOM, fill=X)
frame2 = self.TabNotebook()
frame2.pack(side=TOP,expand=1,fill=BOTH,padx=5,pady=5)
window_info.wm_protocol("WM_DELETE_WINDOW", lambda self=self:self.quitcmd())
def loop(self):
while self.exit < 0:
# There are 2 whiles here. The outer one lets you continue
# after a ^C interrupt.
try:
# This is the replacement for _tkinter mainloop()
# It blocks waiting for the next Tcl event using select.
while self.exit < 0:
self.root.tk.dooneevent(0)
except SystemExit:
# Tkinter uses SystemExit to exit
self.exit = 1
return
except KeyboardInterrupt:
if tkMessageBox.askquestion ('Interrupt', 'Really Quit?') == 'yes':
# self.tk.eval('exit')
self.exit = 1
return
continue
except:
# Otherwise it's some other error - be nice and say why
t, v, tb = sys.exc_info()
text = ""
for line in traceback.format_exception(t,v,tb):
text += line + '\n'
try: tkMessageBox.showerror ('Error', text)
except: pass
self.exit = 1
raise SystemExit, 1
def destroy(self):
self.root.destroy()
if __name__ == '__main__':
root = Tix.Tk()
pyigblast_class = pyigblast_gui(root)
pyigblast_class.build()
pyigblast_class.loop()
pyigblast_class.destroy()
同样在Tix发出的单独但不相关的警告中,我将此输出发送到终端。
(TixForm) Error:Trying to use more than one geometry
manager for the same master window.
Giving up after 50 iterations.
如果有人能告诉我需要改变Tix以保持对话框打开和/或为什么它说我使用两个几何管理器我会很感激!
谢谢, Ĵ
答案 0 :(得分:0)
好的,发出那种声音。
ttk解决方案更清洁,更可定制。这是一个非常优雅的解决方案,概括了这个确切的文件对话框,但使用ttk更清晰。
http://www.pyinmyeye.com/2012/08/tkinter-filedialog-demo.html