【发布时间】:2013-11-29 12:59:54
【问题描述】:
对于 Tk 几何管理器,是否有类似 pack to new line 的东西?我正在使用包将小部件放在框架内。在高分辨率屏幕上,小部件适合并排查找。但是,如果你把它放到一个较小的屏幕上,小部件会在框架中用完。
基本上,我们从:
到:
您可以看到它是如何切断我的处理器输入字段的。相关代码:
options_frame = ttk.LabelFrame(
parent_frame, text="Blast Options")
options_frame.pack(side=TOP, fill=X, expand=1, padx=5, pady=5)
self._set_up_blast_options(options_frame)
def _set_up_blast_options(self, options_frame):
self.evalue = Tkinter.DoubleVar()
self.evalue.set(1)
self.word_size = Tkinter.IntVar()
self.word_size.set(4)
self.penalty_mismatch = Tkinter.DoubleVar()
self.penalty_mismatch.set(-4)
self.min_d_match = Tkinter.IntVar()
self.min_d_match.set(5)
self.proc_count = Tkinter.IntVar()
self.proc_count.set(cpu_count())
# evalue
e_value_label = ttk.LabelFrame(
options_frame, text="e-Value Threshold")
e_value_entry = ttk.Entry(e_value_label)
e_value_entry.insert(0, self.evalue.get())
e_value_entry.bind('<Return>', self._validate_e_value)
e_value_entry.bind('<FocusOut>', self._validate_e_value)
e_value_label.pack(side=LEFT, expand=1, pady=5, padx=5, fill=X)
e_value_entry.pack(side=TOP, expand=1, pady=5, padx=5, fill=X)
# word size
word_size_label = ttk.LabelFrame(
options_frame, text="Word Size")
word_size_entry = ttk.Entry(word_size_label)
word_size_entry.insert(0, self.word_size.get())
word_size_entry.bind('<Return>', self._validate_word_value)
word_size_entry.bind('<FocusOut>', self._validate_word_value)
word_size_label.pack(side=LEFT, expand=1, pady=5, padx=5, fill=X)
word_size_entry.pack(side=TOP, expand=1, pady=5, padx=5, fill=X)
penalty_mismatch_label = ttk.LabelFrame(
options_frame, text="Penalty Mismatch")
penalty_mismatch_entry = ttk.Entry(penalty_mismatch_label)
penalty_mismatch_entry.insert(0, self.penalty_mismatch.get())
penalty_mismatch_entry.bind(
'<Return>', self._validate_penalty_mismatch_value)
penalty_mismatch_entry.bind(
'<FocusOut>', self._validate_penalty_mismatch_value)
penalty_mismatch_label.pack(side=LEFT, expand=1, pady=5,
padx=5, fill=X)
penalty_mismatch_entry.pack(side=TOP, expand=1, pady=5,
padx=5, fill=X)
# Min D Nucleotides
min_d_match_label = ttk.LabelFrame(
options_frame, text="Minimal Number of D Nucleotides")
min_d_match_entry = ttk.Entry(min_d_match_label)
min_d_match_entry.insert(0, self.min_d_match.get())
min_d_match_entry.bind(
'<Return>', self._validate_min_match_value)
min_d_match_entry.bind(
'<FocusOut>', self._validate_min_match_value)
min_d_match_label.pack(side=LEFT, expand=1, pady=5, padx=5, fill=X)
min_d_match_entry.pack(side=TOP, expand=1, pady=5, padx=5, fill=X)
# how many cpus to use
proc_count_label = ttk.LabelFrame(
options_frame, text="Processors")
proc_count_entry = ttk.Entry(proc_count_label)
proc_count_entry.insert(0, self.proc_count.get())
proc_count_entry.bind(
'<Return>', self._validate_proc_count_value)
proc_count_entry.bind(
'<FocusOut>', self._validate_proc_count_value)
proc_count_label.pack(side=LEFT, expand=1, pady=5, padx=5, fill=X)
proc_count_entry.pack(side=TOP, expand=1, pady=5, padx=5, fill=X)
许多事件绑定和选项设置可能不相关,但我认为我仍然应该包括...以防万一。最好的选择是切换到网格管理器吗?问题是这个框架被包装在另一个框架内......等等。是不是一开始用网格管理器,就什么都得用,因为不能在同一个框架里混用打包和网格管理器?
【问题讨论】:
-
您可以在同一个应用程序中混合使用 pack 和 grid —— 事实上,这是推荐的做法。您不能将 grid 和 pack 与具有相同父级的小部件混合使用。
标签: python user-interface tkinter tk ttk