def create_results_view(self): """Add result treeview to labelframe""" self.resultview = ttk.Treeview(master=self, bootstyle=INFO, columns=[0, 1, 2, 3, 4], show=HEADINGS) self.resultview.pack(fill=BOTH, expand=YES, pady=10) # setup columns and use `scale_size` to adjust for resolution self.resultview.heading(0, text='Name', anchor=W) self.resultview.heading(1, text='Modified', anchor=W) self.resultview.heading(2, text='Type', anchor=E) self.resultview.heading(3, text='Size', anchor=E) self.resultview.heading(4, text='Path', anchor=W) self.resultview.column(column=0, anchor=W, width=utility.scale_size(self, 125), stretch=False) self.resultview.column(column=1, anchor=W, width=utility.scale_size(self, 140), stretch=False) self.resultview.column(column=2, anchor=E, width=utility.scale_size(self, 50), stretch=False) self.resultview.column(column=3, anchor=E, width=utility.scale_size(self, 50), stretch=False) self.resultview.column(column=4, anchor=W, width=utility.scale_size(self, 300))
def create_treeview_style(_, style): frame = ttk.Frame(root, padding=5) # title title = ttk.Label(frame, text='Treeview', anchor=tk.CENTER) title.pack(padx=5, pady=2, fill=tk.BOTH) ttk.Separator(frame).pack(padx=5, pady=5, fill=tk.X) # default ttk.Label(frame, text='default').pack(fill=tk.X) tv = ttk.Treeview(frame, columns=[0, 1], height=2) tv.heading('#0', text='Column') for x in range(2): tv.heading(x, text=f'Column {x}') tv.insert('', 'end', text=f'Item {x}', values=[f'Row {x}', f'Row {x+1}']) tv.pack(padx=5, pady=5, fill=tk.BOTH) # colored for color in style.colors: ttk.Label(frame, text=color).pack(fill=tk.X) tv = ttk.Treeview(master=frame, bootstyle=color, columns=[0, 1], height=2) tv.heading('#0', text='Column') for x in range(2): tv.heading(x, text=f'Column {x}') tv.insert('', 'end', text=f'Item {x}', values=[f'Row {x}', f'Row {x+1}']) tv.pack(padx=5, pady=5, fill=tk.BOTH) return frame
'Home': ImageTk.PhotoImage(Image.open(img_path / 'assets/icons8_home_40px.png').resize(SIDEBAR_IMG_SIZE, Image.ANTIALIAS)), 'User': ImageTk.PhotoImage(Image.open(img_path / 'assets/icons8_user_folder_40px.png').resize(SIDEBAR_IMG_SIZE, Image.ANTIALIAS)), 'Desktop': ImageTk.PhotoImage(Image.open(img_path / 'assets/icons8_desktop_40px.png').resize(SIDEBAR_IMG_SIZE, Image.ANTIALIAS)), 'Videos': ImageTk.PhotoImage(Image.open(img_path / 'assets/icons8_movies_folder_40px.png').resize(SIDEBAR_IMG_SIZE, Image.ANTIALIAS)), 'Music': ImageTk.PhotoImage(Image.open(img_path / 'assets/icons8_music_folder_40px.png').resize(SIDEBAR_IMG_SIZE, Image.ANTIALIAS)), 'Pictures': ImageTk.PhotoImage(Image.open(img_path / 'assets/icons8_pictures_folder_40px.png').resize(SIDEBAR_IMG_SIZE, Image.ANTIALIAS)), 'Documents': ImageTk.PhotoImage(Image.open(img_path / 'assets/icons8_documents_folder_40px.png').resize(SIDEBAR_IMG_SIZE, Image.ANTIALIAS)), 'Downloads': ImageTk.PhotoImage(Image.open(img_path / 'assets/icons8_downloads_folder_40px.png').resize(SIDEBAR_IMG_SIZE, Image.ANTIALIAS)), } sidebar = ttk.Frame(name='sidebar') sidebar.pack(side=LEFT, fill=X, anchor=N) contents_tv = ttk.Treeview(name='contentsview', show=TREEHEADINGS, columns=[0, 1, 2]) contents_tv.pack(side=LEFT, fill=ttk.BOTH, expand=ttk.YES) contents_tv.column('#0', width=500) contents_tv.heading('#0', text='Name', anchor=W) contents_tv.heading(0, text='Date modified', anchor=W) contents_tv.column(0, stretch=False) contents_tv.column(1, stretch=False, width=125) contents_tv.heading(1, text='Type', anchor=W) contents_tv.column(2, width=125, anchor=E, stretch=False) contents_tv.heading(2, text='Size', anchor=E) contents_tv.tag_configure('dir', image=images['File']) contents_tv.tag_configure('file', image=images['Dir']) ttk.Button(text='Prev', command=on_click_parent_dir).pack() # crumbframe = ttk.Frame()
top_frame = ttk.Frame(frame) top_frame.pack(fill=tk.BOTH, expand=tk.YES) bot_frame = ttk.Frame(frame) bot_frame.pack(fill=tk.BOTH, expand=tk.YES) for i, color in enumerate(['default', *style.colors]): if color == 'default': text_style = 'default' else: text_style = color + 'inverse' if i < 5: tv = ttk.Treeview( master=top_frame, bootstyle=color, height=5, ) else: tv = ttk.Treeview( master=bot_frame, bootstyle=color, height=5, ) tv.column('#0') tv.heading('#0', text=color, anchor=tk.W) iid = tv.insert('', tk.END, text='parent 1') tv.insert(iid, tk.END, text='child 1') tv.insert(iid, tk.END, text='child 2')
def setup_demo(master): ZEN = """Beautiful is better than ugly. Explicit is better than implicit. Simple is better than complex. Complex is better than complicated. Flat is better than nested. Sparse is better than dense. Readability counts. Special cases aren't special enough to break the rules. Although practicality beats purity. Errors should never pass silently. Unless explicitly silenced. In the face of ambiguity, refuse the temptation to guess. There should be one-- and preferably only one --obvious way to do it. Although that way may not be obvious at first unless you're Dutch. Now is better than never. Although never is often better than *right* now. If the implementation is hard to explain, it's a bad idea. If the implementation is easy to explain, it may be a good idea. Namespaces are one honking great idea -- let's do more of those!""" root = ttk.Frame(master, padding=10) style = ttk.Style() theme_names = style.theme_names() theme_selection = ttk.Frame(root, padding=(10, 10, 10, 0)) theme_selection.pack(fill=X, expand=YES) theme_selected = ttk.Label(master=theme_selection, text="litera", font="-size 24 -weight bold") theme_selected.pack(side=LEFT) lbl = ttk.Label(theme_selection, text="Select a theme:") theme_cbo = ttk.Combobox( master=theme_selection, text=style.theme.name, values=theme_names, ) theme_cbo.pack(padx=10, side=RIGHT) theme_cbo.current(theme_names.index(style.theme.name)) lbl.pack(side=RIGHT) ttk.Separator(root).pack(fill=X, pady=10, padx=10) def change_theme(e): t = cbo.get() style.theme_use(t) theme_selected.configure(text=t) theme_cbo.selection_clear() default.focus_set() theme_cbo.bind("<<ComboboxSelected>>", change_theme) lframe = ttk.Frame(root, padding=5) lframe.pack(side=LEFT, fill=BOTH, expand=YES) rframe = ttk.Frame(root, padding=5) rframe.pack(side=RIGHT, fill=BOTH, expand=YES) color_group = ttk.Labelframe(master=lframe, text="Theme color options", padding=10) color_group.pack(fill=X, side=TOP) for color in style.colors: cb = ttk.Button(color_group, text=color, bootstyle=color) cb.pack(side=LEFT, expand=YES, padx=5, fill=X) rb_group = ttk.Labelframe(lframe, text="Checkbuttons & radiobuttons", padding=10) rb_group.pack(fill=X, pady=10, side=TOP) check1 = ttk.Checkbutton(rb_group, text="selected") check1.pack(side=LEFT, expand=YES, padx=5) check1.invoke() check2 = ttk.Checkbutton(rb_group, text="alternate") check2.pack(side=LEFT, expand=YES, padx=5) check4 = ttk.Checkbutton(rb_group, text="deselected") check4.pack(side=LEFT, expand=YES, padx=5) check4.invoke() check4.invoke() check3 = ttk.Checkbutton(rb_group, text="disabled", state=DISABLED) check3.pack(side=LEFT, expand=YES, padx=5) radio1 = ttk.Radiobutton(rb_group, text="selected", value=1) radio1.pack(side=LEFT, expand=YES, padx=5) radio1.invoke() radio2 = ttk.Radiobutton(rb_group, text="deselected", value=2) radio2.pack(side=LEFT, expand=YES, padx=5) radio3 = ttk.Radiobutton(master=rb_group, text="disabled", value=3, state=DISABLED) radio3.pack(side=LEFT, expand=YES, padx=5) ttframe = ttk.Frame(lframe) ttframe.pack(pady=5, fill=X, side=TOP) table_data = [ ("South Island, New Zealand", 1), ("Paris", 2), ("Bora Bora", 3), ("Maui", 4), ("Tahiti", 5), ] tv = ttk.Treeview(master=ttframe, columns=[0, 1], show=HEADINGS, height=5) for row in table_data: tv.insert("", END, values=row) tv.selection_set("I001") tv.heading(0, text="City") tv.heading(1, text="Rank") tv.column(0, width=300) tv.column(1, width=70, anchor=CENTER) tv.pack(side=LEFT, anchor=NE, fill=X) # # notebook with table and text tabs nb = ttk.Notebook(ttframe) nb.pack(side=LEFT, padx=(10, 0), expand=YES, fill=BOTH) nb_text = "This is a notebook tab.\nYou can put any widget you want here." nb.add(ttk.Label(nb, text=nb_text), text="Tab 1", sticky=NW) nb.add(child=ttk.Label(nb, text="A notebook tab."), text="Tab 2", sticky=NW) nb.add(ttk.Frame(nb), text="Tab 3") nb.add(ttk.Frame(nb), text="Tab 4") nb.add(ttk.Frame(nb), text="Tab 5") # text widget txt = ScrolledText(master=lframe, height=5, width=50, autohide=True) txt.insert(END, ZEN) txt.pack(side=LEFT, anchor=NW, pady=5, fill=BOTH, expand=YES) lframe_inner = ttk.Frame(lframe) lframe_inner.pack(fill=BOTH, expand=YES, padx=10) s1 = ttk.Scale(master=lframe_inner, orient=HORIZONTAL, value=75, from_=100, to=0) s1.pack(fill=X, pady=5, expand=YES) ttk.Progressbar( master=lframe_inner, orient=HORIZONTAL, value=50, ).pack(fill=X, pady=5, expand=YES) ttk.Progressbar( master=lframe_inner, orient=HORIZONTAL, value=75, bootstyle=(SUCCESS, STRIPED), ).pack(fill=X, pady=5, expand=YES) m = ttk.Meter( master=lframe_inner, metersize=150, amountused=45, subtext="meter widget", bootstyle=INFO, interactive=True, ) m.pack(pady=10) sb = ttk.Scrollbar( master=lframe_inner, orient=HORIZONTAL, ) sb.set(0.1, 0.9) sb.pack(fill=X, pady=5, expand=YES) sb = ttk.Scrollbar(master=lframe_inner, orient=HORIZONTAL, bootstyle=(DANGER, ROUND)) sb.set(0.1, 0.9) sb.pack(fill=X, pady=5, expand=YES) btn_group = ttk.Labelframe(master=rframe, text="Buttons", padding=(10, 5)) btn_group.pack(fill=X) menu = ttk.Menu(root) for i, t in enumerate(style.theme_names()): menu.add_radiobutton(label=t, value=i) default = ttk.Button(master=btn_group, text="solid button") default.pack(fill=X, pady=5) default.focus_set() mb = ttk.Menubutton( master=btn_group, text="solid menubutton", bootstyle=SECONDARY, menu=menu, ) mb.pack(fill=X, pady=5) cb = ttk.Checkbutton( master=btn_group, text="solid toolbutton", bootstyle=(SUCCESS, TOOLBUTTON), ) cb.invoke() cb.pack(fill=X, pady=5) ob = ttk.Button( master=btn_group, text="outline button", bootstyle=(INFO, OUTLINE), command=lambda: Messagebox.ok("You pushed an outline button"), ) ob.pack(fill=X, pady=5) mb = ttk.Menubutton( master=btn_group, text="outline menubutton", bootstyle=(WARNING, OUTLINE), menu=menu, ) mb.pack(fill=X, pady=5) cb = ttk.Checkbutton( master=btn_group, text="outline toolbutton", bootstyle=(SUCCESS, OUTLINE, TOOLBUTTON), ) cb.pack(fill=X, pady=5) lb = ttk.Button(master=btn_group, text="link button", bootstyle=LINK) lb.pack(fill=X, pady=5) cb1 = ttk.Checkbutton( master=btn_group, text="rounded toggle", bootstyle=(SUCCESS, ROUND, TOGGLE), ) cb1.invoke() cb1.pack(fill=X, pady=5) cb2 = ttk.Checkbutton(master=btn_group, text="squared toggle", bootstyle=(SQUARE, TOGGLE)) cb2.pack(fill=X, pady=5) cb2.invoke() input_group = ttk.Labelframe(master=rframe, text="Other input widgets", padding=10) input_group.pack(fill=BOTH, pady=(10, 5), expand=YES) entry = ttk.Entry(input_group) entry.pack(fill=X) entry.insert(END, "entry widget") password = ttk.Entry(master=input_group, show="•") password.pack(fill=X, pady=5) password.insert(END, "password") spinbox = ttk.Spinbox(master=input_group, from_=0, to=100) spinbox.pack(fill=X) spinbox.set(45) cbo = ttk.Combobox( master=input_group, text=style.theme.name, values=theme_names, exportselection=False, ) cbo.pack(fill=X, pady=5) cbo.current(theme_names.index(style.theme.name)) de = ttk.DateEntry(input_group) de.pack(fill=X) return root
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.pack(fill=BOTH, expand=YES) image_files = { 'properties-dark': 'icons8_settings_24px.png', 'properties-light': 'icons8_settings_24px_2.png', 'add-to-backup-dark': 'icons8_add_folder_24px.png', 'add-to-backup-light': 'icons8_add_book_24px.png', 'stop-backup-dark': 'icons8_cancel_24px.png', 'stop-backup-light': 'icons8_cancel_24px_1.png', 'play': 'icons8_play_24px_1.png', 'refresh': 'icons8_refresh_24px_1.png', 'stop-dark': 'icons8_stop_24px.png', 'stop-light': 'icons8_stop_24px_1.png', 'opened-folder': 'icons8_opened_folder_24px.png', 'logo': 'backup.png' } self.photoimages = [] imgpath = Path(__file__).parent / 'assets' for key, val in image_files.items(): _path = imgpath / val self.photoimages.append(ttk.PhotoImage(name=key, file=_path)) # buttonbar buttonbar = ttk.Frame(self, style='primary.TFrame') buttonbar.pack(fill=X, pady=1, side=TOP) ## new backup _func = lambda: Messagebox.ok(message='Adding new backup') btn = ttk.Button(master=buttonbar, text='New backup set', image='add-to-backup-light', compound=LEFT, command=_func) btn.pack(side=LEFT, ipadx=5, ipady=5, padx=(1, 0), pady=1) ## backup _func = lambda: Messagebox.ok(message='Backing up...') btn = ttk.Button(master=buttonbar, text='Backup', image='play', compound=LEFT, command=_func) btn.pack(side=LEFT, ipadx=5, ipady=5, padx=0, pady=1) ## refresh _func = lambda: Messagebox.ok(message='Refreshing...') btn = ttk.Button(master=buttonbar, text='Refresh', image='refresh', compound=LEFT, command=_func) btn.pack(side=LEFT, ipadx=5, ipady=5, padx=0, pady=1) ## stop _func = lambda: Messagebox.ok(message='Stopping backup.') btn = ttk.Button(master=buttonbar, text='Stop', image='stop-light', compound=LEFT, command=_func) btn.pack(side=LEFT, ipadx=5, ipady=5, padx=0, pady=1) ## settings _func = lambda: Messagebox.ok(message='Changing settings') btn = ttk.Button(master=buttonbar, text='Settings', image='properties-light', compound=LEFT, command=_func) btn.pack(side=LEFT, ipadx=5, ipady=5, padx=0, pady=1) # left panel left_panel = ttk.Frame(self, style='bg.TFrame') left_panel.pack(side=LEFT, fill=Y) ## backup summary (collapsible) bus_cf = CollapsingFrame(left_panel) bus_cf.pack(fill=X, pady=1) ## container bus_frm = ttk.Frame(bus_cf, padding=5) bus_frm.columnconfigure(1, weight=1) bus_cf.add(child=bus_frm, title='Backup Summary', bootstyle=SECONDARY) ## destination lbl = ttk.Label(bus_frm, text='Destination:') lbl.grid(row=0, column=0, sticky=W, pady=2) lbl = ttk.Label(bus_frm, textvariable='destination') lbl.grid(row=0, column=1, sticky=EW, padx=5, pady=2) self.setvar('destination', 'd:/test/') ## last run lbl = ttk.Label(bus_frm, text='Last Run:') lbl.grid(row=1, column=0, sticky=W, pady=2) lbl = ttk.Label(bus_frm, textvariable='lastrun') lbl.grid(row=1, column=1, sticky=EW, padx=5, pady=2) self.setvar('lastrun', '14.06.2021 19:34:43') ## files Identical lbl = ttk.Label(bus_frm, text='Files Identical:') lbl.grid(row=2, column=0, sticky=W, pady=2) lbl = ttk.Label(bus_frm, textvariable='filesidentical') lbl.grid(row=2, column=1, sticky=EW, padx=5, pady=2) self.setvar('filesidentical', '15%') ## section separator sep = ttk.Separator(bus_frm, bootstyle=SECONDARY) sep.grid(row=3, column=0, columnspan=2, pady=10, sticky=EW) ## properties button _func = lambda: Messagebox.ok(message='Changing properties') bus_prop_btn = ttk.Button(master=bus_frm, text='Properties', image='properties-dark', compound=LEFT, command=_func, bootstyle=LINK) bus_prop_btn.grid(row=4, column=0, columnspan=2, sticky=W) ## add to backup button _func = lambda: Messagebox.ok(message='Adding to backup') add_btn = ttk.Button(master=bus_frm, text='Add to backup', image='add-to-backup-dark', compound=LEFT, command=_func, bootstyle=LINK) add_btn.grid(row=5, column=0, columnspan=2, sticky=W) # backup status (collapsible) status_cf = CollapsingFrame(left_panel) status_cf.pack(fill=BOTH, pady=1) ## container status_frm = ttk.Frame(status_cf, padding=10) status_frm.columnconfigure(1, weight=1) status_cf.add(child=status_frm, title='Backup Status', bootstyle=SECONDARY) ## progress message lbl = ttk.Label(master=status_frm, textvariable='prog-message', font='Helvetica 10 bold') lbl.grid(row=0, column=0, columnspan=2, sticky=W) self.setvar('prog-message', 'Backing up...') ## progress bar pb = ttk.Progressbar(master=status_frm, variable='prog-value', bootstyle=SUCCESS) pb.grid(row=1, column=0, columnspan=2, sticky=EW, pady=(10, 5)) self.setvar('prog-value', 71) ## time started lbl = ttk.Label(status_frm, textvariable='prog-time-started') lbl.grid(row=2, column=0, columnspan=2, sticky=EW, pady=2) self.setvar('prog-time-started', 'Started at: 14.06.2021 19:34:56') ## time elapsed lbl = ttk.Label(status_frm, textvariable='prog-time-elapsed') lbl.grid(row=3, column=0, columnspan=2, sticky=EW, pady=2) self.setvar('prog-time-elapsed', 'Elapsed: 1 sec') ## time remaining lbl = ttk.Label(status_frm, textvariable='prog-time-left') lbl.grid(row=4, column=0, columnspan=2, sticky=EW, pady=2) self.setvar('prog-time-left', 'Left: 0 sec') ## section separator sep = ttk.Separator(status_frm, bootstyle=SECONDARY) sep.grid(row=5, column=0, columnspan=2, pady=10, sticky=EW) ## stop button _func = lambda: Messagebox.ok(message='Stopping backup') btn = ttk.Button(master=status_frm, text='Stop', image='stop-backup-dark', compound=LEFT, command=_func, bootstyle=LINK) btn.grid(row=6, column=0, columnspan=2, sticky=W) ## section separator sep = ttk.Separator(status_frm, bootstyle=SECONDARY) sep.grid(row=7, column=0, columnspan=2, pady=10, sticky=EW) # current file message lbl = ttk.Label(status_frm, textvariable='current-file-msg') lbl.grid(row=8, column=0, columnspan=2, pady=2, sticky=EW) self.setvar('current-file-msg', 'Uploading: d:/test/settings.txt') # logo lbl = ttk.Label(left_panel, image='logo', style='bg.TLabel') lbl.pack(side='bottom') # right panel right_panel = ttk.Frame(self, padding=(2, 1)) right_panel.pack(side=RIGHT, fill=BOTH, expand=YES) ## file input browse_frm = ttk.Frame(right_panel) browse_frm.pack(side=TOP, fill=X, padx=2, pady=1) file_entry = ttk.Entry(browse_frm, textvariable='folder-path') file_entry.pack(side=LEFT, fill=X, expand=YES) btn = ttk.Button(master=browse_frm, image='opened-folder', bootstyle=(LINK, SECONDARY), command=self.get_directory) btn.pack(side=RIGHT) ## Treeview tv = ttk.Treeview(right_panel, show='headings', height=5) tv.configure(columns=('name', 'state', 'last-modified', 'last-run-time', 'size')) tv.column('name', width=150, stretch=True) for col in ['last-modified', 'last-run-time', 'size']: tv.column(col, stretch=False) for col in tv['columns']: tv.heading(col, text=col.title(), anchor=W) tv.pack(fill=X, pady=1) ## scrolling text output scroll_cf = CollapsingFrame(right_panel) scroll_cf.pack(fill=BOTH, expand=YES) output_container = ttk.Frame(scroll_cf, padding=1) _value = 'Log: Backing up... [Uploading file: D:/sample_file_35.txt]' self.setvar('scroll-message', _value) st = ScrolledText(output_container) st.pack(fill=BOTH, expand=YES) scroll_cf.add(output_container, textvariable='scroll-message') # seed with some sample data ## starting sample directory file_entry.insert(END, 'D:/text/myfiles/top-secret/samples/') ## treeview and backup logs for x in range(20, 35): result = choices(['Backup Up', 'Missed in Destination'])[0] st.insert(END, f'19:34:{x}\t\t Uploading: D:/file_{x}.txt\n') st.insert(END, f'19:34:{x}\t\t Upload {result}.\n') timestamp = datetime.now().strftime('%d.%m.%Y %H:%M:%S') tv.insert('', END, x, values=(f'sample_file_{x}.txt', result, timestamp, timestamp, f'{int(x // 3)} MB')) tv.selection_set(20)
def create_left_frame(self): """Create all the left frame widgets""" container = ttk.Frame(self) container.pack(side=LEFT, fill=BOTH, expand=YES, padx=5) # demonstrates all color options inside a label color_group = ttk.Labelframe(master=container, text="Theme color options", padding=10) color_group.pack(fill=X, side=TOP) for color in self.style.colors: cb = ttk.Button(color_group, text=color, bootstyle=color) cb.pack(side=LEFT, expand=YES, padx=5, fill=X) # demonstrates all radiobutton widgets active and disabled cr_group = ttk.Labelframe(master=container, text="Checkbuttons & radiobuttons", padding=10) cr_group.pack(fill=X, pady=10, side=TOP) cr1 = ttk.Checkbutton(cr_group, text="selected") cr1.pack(side=LEFT, expand=YES, padx=5) cr1.invoke() cr2 = ttk.Checkbutton(cr_group, text="deselected") cr2.pack(side=LEFT, expand=YES, padx=5) cr3 = ttk.Checkbutton(cr_group, text="disabled", state=DISABLED) cr3.pack(side=LEFT, expand=YES, padx=5) cr4 = ttk.Radiobutton(cr_group, text="selected", value=1) cr4.pack(side=LEFT, expand=YES, padx=5) cr4.invoke() cr5 = ttk.Radiobutton(cr_group, text="deselected", value=2) cr5.pack(side=LEFT, expand=YES, padx=5) cr6 = ttk.Radiobutton(cr_group, text="disabled", value=3, state=DISABLED) cr6.pack(side=LEFT, expand=YES, padx=5) # demonstrates the treeview and notebook widgets ttframe = ttk.Frame(container) ttframe.pack(pady=5, fill=X, side=TOP) table_data = [ ("South Island, New Zealand", 1), ("Paris", 2), ("Bora Bora", 3), ("Maui", 4), ("Tahiti", 5), ] tv = ttk.Treeview(master=ttframe, columns=[0, 1], show="headings", height=5) for row in table_data: tv.insert("", END, values=row) tv.selection_set("I001") tv.heading(0, text="City") tv.heading(1, text="Rank") tv.column(0, width=300) tv.column(1, width=70, anchor=CENTER) tv.pack(side=LEFT, anchor=NE, fill=X) nb = ttk.Notebook(ttframe) nb.pack(side=LEFT, padx=(10, 0), expand=YES, fill=BOTH) nb_text = ( "This is a notebook tab.\nYou can put any widget you want here.") nb.add(ttk.Label(nb, text=nb_text), text="Tab 1", sticky=NW) nb.add( child=ttk.Label(nb, text="A notebook tab."), text="Tab 2", sticky=NW, ) nb.add(ttk.Frame(nb), text="Tab 3") nb.add(ttk.Frame(nb), text="Tab 4") nb.add(ttk.Frame(nb), text="Tab 5") # text widget txt = ttk.Text(master=container, height=5, width=50, wrap="none") txt.insert(END, DemoWidgets.ZEN) txt.pack(side=LEFT, anchor=NW, pady=5, fill=BOTH, expand=YES) # demonstrates scale, progressbar, and meter, and scrollbar widgets lframe_inner = ttk.Frame(container) lframe_inner.pack(fill=BOTH, expand=YES, padx=10) scale = ttk.Scale(master=lframe_inner, orient=HORIZONTAL, value=75, from_=100, to=0) scale.pack(fill=X, pady=5, expand=YES) ttk.Progressbar( master=lframe_inner, orient=HORIZONTAL, value=50, ).pack(fill=X, pady=5, expand=YES) ttk.Progressbar( master=lframe_inner, orient=HORIZONTAL, value=75, bootstyle="success-striped", ).pack(fill=X, pady=5, expand=YES) m = ttk.Meter( master=lframe_inner, metersize=150, amountused=45, subtext="meter widget", bootstyle="info", interactive=True, ) m.pack(pady=10) sb = ttk.Scrollbar( master=lframe_inner, orient=HORIZONTAL, ) sb.set(0.1, 0.9) sb.pack(fill=X, pady=5, expand=YES) sb = ttk.Scrollbar(master=lframe_inner, orient=HORIZONTAL, bootstyle="danger-round") sb.set(0.1, 0.9) sb.pack(fill=X, pady=5, expand=YES)
def __init__(self, master: "FBWidgetCanvas"): super().__init__(master) self.protocol("WM_DELETE_WINDOW", master.destroyCmdTable) self.tableFrame = ttk.Frame(self) self.tableFrame.pack(fill="both", expand=True) self.buttonFrame = ttk.Frame(self) self.buttonFrame.pack(fill="x", ipadx=5, ipady=5) self.tree = ttk.Treeview( self.tableFrame, columns=["name", "command", "variable", "binding"], show="headings") self.scrollbar = ttk.Scrollbar(self.tableFrame, orient="vertical", command=self.tree.yview) self.tree.configure(yscrollcommand=self.scrollbar.set) self.scrollbar.pack(side="right", fill="y") self.tree.pack(side="right", fill="both", expand=True) self.tree.heading("name", text="名称", anchor="w") self.tree.heading("command", text="指令", anchor="e") self.tree.heading("variable", text="变量", anchor="e") self.tree.heading("binding", text="绑定", anchor="e") self.tree.column("name", width=80, anchor="w") self.tree.column("command", width=200, anchor="e") self.tree.column("variable", width=200, anchor="e") self.tree.column("binding", width=200, anchor="e") self.tree.bind("<<TreeviewSelect>>", self._onSelect) self.tree.bind("<Double-1>", self._onDoubleClick) self.btn_close = ttk.Button(self.buttonFrame, text="关闭", command=master.destroyCmdTable) self.btn_add = ttk.Button(self.buttonFrame, text="添加", command=self._add) self.btn_dup = ttk.Button(self.buttonFrame, text="复制", command=self._dup) self.btn_del = ttk.Button(self.buttonFrame, text="删除", command=self._delete) self.btn_edit = ttk.Button(self.buttonFrame, text="编辑", command=self._edit) self.btn_up = ttk.Button(self.buttonFrame, text="上移", command=self._up) self.btn_down = ttk.Button(self.buttonFrame, text="下移", command=self._down) for btn in ( self.btn_close, self.btn_add, self.btn_dup, self.btn_del, self.btn_edit, self.btn_up, self.btn_down, ): btn.pack(side="left", expand=True) self._state = "!disabled" self._checkSel() self.cmdDict = master.cmdDict for v in master.cmdList: self.tree.insert("", "end", values=v)