我的目标是要有一个标签列表,这些标签放在一个列表的标签框架实例中,这些实例放在一个列表中的笔记本中,依此类推。
出现窗口,并放置笔记本选项卡。我还可以将Tkinter LabelFrames单独添加到笔记本选项卡,然后将标签分别添加到每个标签框架,但这根本没有效果。
在这一点上,我似乎无法发现为什么LabelFrame实例不会出现在选项卡中。 MyLabelFrames
类是否正确创建?实例创建正确吗?我找不到有关创建LabelFrame类的文档。
import tkinter as tk
from tkinter import ttk
from HH_search import HandHistory
class GUI(tk.Tk):
def __init__(self):
super().__init__()
self.title("Hand History Equilibrium Analyzer")
self.geometry('900x700')
self.resizable(width=False, height=False)
names = ['Hand History Analyzer', 'Tree Loader']
frames = ['Hand History', 'Solver']
hh_labels = ['Info:', 'Players:', 'Pre-flop:',
'Flop:', 'Turn:', 'River:']
self.nb = self.create_notebook(names)
self.menu = self.create_menus()
self.frame = self.create_frames(frames)
tree_tab = self.nb.tabs['Tree Loader']
positions = ['BTN', 'CO', 'MP', 'EP', 'SB', 'BB']
var = tk.StringVar()
var.set(positions[0])
for player in positions:
ttk.Radiobutton(
tree_tab, text=player, variable=var,
value=player, command=False).grid(column=0, sticky=tk.W)
self.mainloop()
def create_notebook(self, names):
nb = MyNotebook(self, names)
nb.grid(sticky=tk.NSEW)
hh_tab = nb.tabs['Hand History Analyzer']
hh_btn = ttk.Button(
hh_tab, text='Begin Hand History Analysis',
command=lambda: HandHistory.analyze_hand(self))
hh_btn.pack(side="top", fill="x", expand=False)
return nb
def create_menus(self):
menu = tk.Menu(self, tearoff=False)
self.config(menu=menu)
sub_menu = tk.Menu(menu, tearoff=False)
menu.add_cascade(label="File", menu=sub_menu)
sub_menu.add_separator()
sub_menu.add_command(label='Exit', command=self.destroy)
return menu
def create_frames(self, frames):
frm = MyLabelFrames(self, frames)
frm.grid(sticky=tk.NSEW)
frame1 = frm.frames['Hand History']
lbltest1 = ttk.Label(frame1, text='test')
lbltest1.pack(side="top", fill="x", expand=False)
return frm
class MyNotebook(ttk.Notebook):
def __init__(self, master, names):
super().__init__(master, width=897, height=675)
self.tabs = {}
for name in names:
self.tabs[name] = tab = ttk.Frame(self)
self.add(tab, text=name)
class MyLabelFrames(ttk.LabelFrame):
def __init__(self, master, frames):
super().__init__(master)
self.frames = {}
for frame in frames:
self.frames[frame] = ttk.LabelFrame(self, text=frames)
GUI()