0

我意识到第一个建议是“停止使用 Tix”,但我喜欢一些小部件,即使它们自 08 年以来就没有维护过。我注意到的一件事是某些对话框不会保持打开状态。例如,我在笔记本小部件内的 LabelFrame 小部件内使用 FileEntry 小部件。文件对话框如下所示。

全文件条目

当您单击文件对话框按钮时,您会得到:

选择

红色箭头显示了该过滤器中文件的下拉列表,但是当我单击它时没有任何反应。您可以看到一个短暂的闪烁(例如几毫秒),例如检查了事件循环或其他内容,但随后什么也没有。与 FileEntry 上的其他按钮相同。

有关此的完整代码,您可以在此处查看

我认为相关部分是:

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 进行哪些更改以保持对话框打开和/或为什么它说我正在使用两个几何管理器,我将不胜感激!

谢谢,J

4

1 回答 1

0

好的,发出声音。

ttk 解决方案更加简洁和可定制。这是一个非常优雅的解决方案,概括了这个确切的文件对话框,但使用 ttk 更简洁。

http://www.pyinmyeye.com/2012/08/tkinter-filedialog-demo.html

于 2013-11-06T23:30:25.613 回答