def control_panel(): mf = ttk.LabelFrame(right_frame) mf.grid(column=0, row=0, padx=8, pady=4) mf.grid_rowconfigure(2, minsize=10) def start(): global PAUSE_STATUS global int_i PAUSE_STATUS = False if bt_alg.get() == 'UC': dijkstra_search((0, 0), (24, 24)) if bt_alg.get() == 'A*': a_star_search((0, 0), (24, 24)) pause_button.configure(background='SystemButtonFace') start_button.configure(background='green') def pause(): global PAUSE_STATUS PAUSE_STATUS = True pause_button.configure(background='red') start_button.configure(background='SystemButtonFace') start_button = tk.Button(mf, text="Start", command=start, width=10) start_button.grid(row=1, column=1, sticky='w', padx=5, pady=5) pause_button = tk.Button(mf, text="Pause", command=pause, width=10) pause_button.grid(row=2, column=1, sticky='w', padx=5, pady=5) def sel(): print('algorithm =', bt_alg.get()) r1_button = tk.Radiobutton(mf, text='UC', value='UC', variable=bt_alg, command=sel) r2_button = tk.Radiobutton(mf, text='A*', value='A*', variable=bt_alg, command=sel) bt_alg.set('UC') r1_button.grid(row=3, column=1, columnspan=2, sticky='w') r2_button.grid(row=4, column=1, columnspan=2, sticky='w') def box_update1(): print('speed is set to:', box1.get()) def box_update2(): print('prob. blocking is set to:', box2.get()) lf = ttk.LabelFrame(right_frame, relief="sunken") lf.grid(column=0, row=1, padx=5, pady=5) ttk.Label(lf, text="Speed ").grid(row=1, column=1, sticky='w') box1 = ttk.Combobox(lf, textvariable=speed, state='readonly', width=6) box1.grid(row=2, column=1, sticky='w') box1['values'] = tuple(str(i) for i in range(10)) box1.current(5) box1.bind("<<ComboboxSelected>>", box_update1) ttk.Label(lf, text="Prob. blocking").grid(row=3, column=1, sticky='w') box2 = ttk.Combobox(lf, textvariable=prob, state='readonly', width=6) box2.grid(row=4, column=1, sticky='ew') box2['values'] = tuple(str(i) for i in range(10)) box2.current(3) box2.bind("<<ComboboxSelected>>", box_update2) def draw_line_on_grid(canvas, i): if PAUSE_STATUS is False: plot_line_segment(canvas, i, i, i, i+1) plot_line_segment(canvas, i, i+1, i+1, i+1) threading.Timer(int(box1.get()), draw_line_on_grid, [canvas, i+1]).start() def print_something_for_testing(): if PAUSE_STATUS is False: threading.Timer(int(box1.get()), print_something_for_testing).start()
# create three Radiobuttons using one variable rad_var = tk.IntVar() # we selects a non-existing index value for rad_var rad_var.set(99) # create all three Radiobutton widgets within in one loop for col in range(3): cur_rad = ttk.Radiobutton(win, text=colors[col], variable=rad_var, value=col, command=rad_call ).grid(row=6, column=col, sticky=tk.W) # create a container to hold labels buttons_frame = ttk.LabelFrame(win, text='') # no LabelFrame name buttons_frame.grid( row=7, column=0, padx=20, pady=40 # add padding space around widget ) # place labels into the container element for col in range(3): ttk.Label( buttons_frame, # notice the parent text=f'Label {col+1}' ).grid( row=col, column=0, sticky=tk.W )
def __init__(self, master): self.frame = ttk.LabelFrame(master, text="Information") self.remoteness_info = ttk.Label(self.frame, text="") self.remoteness_info.grid(row=0, column=0)
# Simple GUI to explain LabelFrame import tkinter as tk from tkinter import ttk window = tk.Tk() window.title("LabelFrame Example") window.geometry("300x250") window.resizable(0, 0) window.wm_iconbitmap("images/ok.ico") lab_frame = ttk.LabelFrame(window, text="Personal information:") lab_frame.pack(pady=20) name = ttk.Label(lab_frame, text="Full name:") name.grid(column=0, row=0, padx=10, pady=20) entry_name = ttk.Entry(lab_frame) entry_name.grid(column=1, row=0, padx=20) etc = ttk.Label(lab_frame, text="Other widgets here...") etc.grid(column=0, row=2) btn = ttk.Button(window, text="Send info") btn.pack(pady=30) window.mainloop()
def create_widgets(self): """ - Title (Exchange/Market) - Subheading (Backtest interval) - Data display - Quit button """ ### Create Frames #### self.trade_frame = {'master': ttk.Frame(self.root)} logger.debug('self.trade_frame: ' + str(self.trade_frame)) self.analysis_frame = { 'master': ttk.Frame(self.root), 'buys': None, 'sells': None, 'all': None } analysis_main_subframes = { 'buys': { 'main': ttk.LabelFrame(self.analysis_frame['master'], text='Buys') }, 'sells': { 'main': ttk.LabelFrame(self.analysis_frame['master'], text='Sells') }, 'all': { 'main': ttk.LabelFrame(self.analysis_frame['master'], text='All') } } self.analysis_frame.update(analysis_main_subframes) analysis_period_subframes = { 'buys': { 'current': ttk.LabelFrame(self.analysis_frame['buys']['main'], text='Current'), 'last': ttk.LabelFrame(self.analysis_frame['buys']['main'], text='Last'), 'difference': ttk.LabelFrame(self.analysis_frame['buys']['main'], text='Difference') }, 'sells': { 'current': ttk.LabelFrame(self.analysis_frame['sells']['main'], text='Current'), 'last': ttk.LabelFrame(self.analysis_frame['sells']['main'], text='Last'), 'difference': ttk.LabelFrame(self.analysis_frame['sells']['main'], text='Difference') }, 'all': { 'current': ttk.LabelFrame(self.analysis_frame['all']['main'], text='Current'), 'last': ttk.LabelFrame(self.analysis_frame['all']['main'], text='Last'), 'difference': ttk.LabelFrame(self.analysis_frame['all']['main'], text='Difference') } } self.analysis_frame.update(analysis_period_subframes) logger.debug('self.analysis_frame: ' + str(self.analysis_frame)) self.menu_frame = {'master': ttk.Frame(self.root)} logger.debug('self.menu_frame: ' + str(self.menu_frame)) #### Create Widgets #### # Create dictionary for widget storage self.widgets = { 'trade': { 'titles': {}, 'text': {}, 'variables': {} }, 'analysis': { 'titles': {}, 'buys': { 'titles': {}, 'text': {}, 'variables': {} }, 'sells': { 'titles': {}, 'text': {}, 'variables': {} }, 'all': { 'titles': {}, 'text': {}, 'variables': {} } }, 'menu': { 'titles': {}, 'text': {}, 'variables': {}, 'buttons': {}, 'listboxes': {}, 'comboboxes': {} } } ## Trade Frame ## # Trade Titles self.widgets['trade']['titles']['main'] = ttk.Label( self.trade_frame['master'], text='Last Trade') self.colors[ 'transparent'] = self.widgets['trade']['titles']['main'].cget( 'bg') # Save OS-dependent "transparent" background color name logger.debug('self.colors[\'transparent\']: ' + self.colors['transparent']) # Trade Text Labels self.widgets['trade']['text']['price'] = ttk.Label( self.trade_frame['master'], text='Price:') self.widgets['trade']['text']['quantity'] = ttk.Label( self.trade_frame['master'], text='Quantity:') self.widgets['trade']['text']['amount'] = ttk.Label( self.trade_frame['master'], text='Amount:') # Trade Variables self.widgets['trade']['variables']['price'] = ttk.Label( self.trade_frame['master'], textvariable=self.variables['trade']['price'], compound=ttk.RIGHT) self.widgets['trade']['variables']['quantity'] = ttk.Label( self.trade_frame['master'], textvariable=self.variables['trade']['quantity']) self.widgets['trade']['variables']['amount'] = ttk.Label( self.trade_frame['master'], textvariable=self.variables['trade']['amount']) ## Analysis Frame ## # Analysis Titles self.widgets['analysis']['titles']['main'] = ttk.Label( self.analysis_frame['master'], text='Analysis Info') # Analysis Text Labels trade_types = ['buys', 'sells', 'all'] categories = ['current', 'last', 'difference'] for trade_type in trade_types: logger.debug('trade_type: ' + trade_type) for category in categories: logger.debug('category: ' + category) """ self.widgets['analysis'][trade_type][category]['text']['volume'] self.widgets['analysis'][trade_type][category]['text']['price'] self.widgets['analysis'][trade_type][category]'text']['amount'] self.widgets['analysis'][trade_type][category]'text']['count'] self.widgets['analysis'][trade_type][category]'text']['rate_volume'] self.widgets['analysis'][trade_type][category]'text']['rate_amount'] self.widgets['analysis'][trade_type][category]'text']['rate_count'] self.widgets['analysis'][trade_type][category]'variables']['volume'] self.widgets['analysis'][trade_type][category]'variables']['price'] self.widgets['analysis'][trade_type][category]'variables']['amount'] self.widgets['analysis'][trade_type][category]'variables']['count'] self.widgets['analysis'][trade_type][category]'variables']['rate_volume'] self.widgets['analysis'][trade_type][category]'variables']['rate_amount'] self.widgets['analysis'][trade_type][category]'variables']['rate_count'] """ ## Menu Frame ## # Status self.widgets['menu']['variables']['status'] = ttk.Label( self.menu_frame['master'], textvariable=self.variables['trade']['status']) # Buttons self.widgets['menu']['buttons']['quit'] = ttk.Button( self.menu_frame['master'], text='Quit', command=self.stop_display) # Comboboxes self.widgets['menu']['comboboxes']['exchange'] = ttk.Combobox( self.menu_frame['master'], textvariable=self.variables['menu']['exchange'], values=self.available_exchanges) self.widgets['menu']['comboboxes']['market'] = ttk.Combobox( self.menu_frame['master'], textvariable=self.variables['menu']['market'], values=self.available_markets) self.widgets['menu']['comboboxes']['interval'] = ttk.Combobox( self.menu_frame['master'], textvariable=self.variables['menu']['interval'], values=self.available_intervals) #for combo in self.widgets['menu']['comboboxes']: #pass """ def OptionCallBack(*args): print variable.get() print so.current() variable = StringVar(app) variable.set("Select From List") variable.trace('w', OptionCallBack) so = ttk.Combobox(app, textvariable=variable) so.config(values =('Tracing Upstream', 'Tracing Downstream','Find Path')) so.grid(row=1, column=4, sticky='E', padx=10) """ ## Format Text ## formatting_frames = ['trade', 'analysis'] for frame in formatting_frames: for category in self.widgets[frame]: logger.debug('category: ' + category) for element in self.widgets[frame][category]: logger.debug('element: ' + element) if frame == 'analysis' and category != 'titles': for elem in self.widgets[frame][category][element]: logger.debug('elem: ' + elem) selected_font = self.fonts[elem] logger.debug('selected_font: ' + str(selected_font)) self.widgets[frame][category][element][ elem].config(font=selected_font) if category == 'variables': self.widgets[frame][category][element][ elem].config( bg=self.colors['bg']['updating']) else: selected_font = self.fonts[category] logger.debug('selected_font: ' + str(selected_font)) self.widgets[frame][category][element].config( font=selected_font) if category == 'variables': self.widgets[frame][category][element].config( bg=self.colors['bg']['updating']) ## Create Grid Layout ## # Frames self.trade_frame['master'].grid(row=0, column=0) self.analysis_frame['master'].grid(row=0, column=1) self.menu_frame['master'].grid(row=1) #, column=0, columnspan=2) # Trade Frame self.widgets['trade']['titles']['main'].grid(row=0, columnspan=2) self.widgets['trade']['text']['price'].grid(row=1, column=0, sticky=tk.E) self.widgets['trade']['variables']['price'].grid(row=1, column=1, sticky=tk.W) self.widgets['trade']['text']['quantity'].grid(row=2, column=0, sticky=tk.E) self.widgets['trade']['variables']['quantity'].grid(row=2, column=1, sticky=tk.W) self.widgets['trade']['text']['amount'].grid(row=3, column=0, sticky=tk.E) self.widgets['trade']['variables']['amount'].grid(row=3, column=1, sticky=tk.W) # Analysis Frame self.widgets['analysis']['titles']['main'].grid(row=0, columnspan=2) # Menus Frame self.widgets['menu']['variables']['status'].grid( row=0, column=0 ) #, sticky=tk.W)#row=4, column=0, columnspan=2, sticky=tk.E+tk.W) self.widgets['menu']['buttons']['quit'].grid(row=0, column=1) #, sticky=tk.E) self.widgets['menu']['comboboxes']['exchange'].grid(row=0, column=2) self.widgets['menu']['comboboxes']['market'].grid(row=0, column=3) self.widgets['menu']['comboboxes']['interval'].grid(row=0, column=4) # Variables to signal state of data self.trade_data_ready = False self.analysis_data_ready = False self.gui_data_ready = False
win = tk.Tk() # Add a title win.title("Python GUI") tabControl = ttk.Notebook(win) # Create Tab Control tab1 = ttk.Frame(tabControl) # Create a tab tabControl.add(tab1, text='Tab 1') # Add the tab tab2 = ttk.Frame(tabControl) # Add a second tab tabControl.add(tab2, text='Tab 2') # Make second tab visible tabControl.pack(expand=1, fill="both") # Pack to make visible # LabelFrame using tab1 as the parent mighty = ttk.LabelFrame(tab1, text=' Mighty Python ') mighty.grid(column=0, row=0, padx=8, pady=4) # Modify adding a Label using mighty as the parent instead of win a_label = ttk.Label(mighty, text="Enter a name:") a_label.grid(column=0, row=0, sticky='W') # Modified Button Click Function def click_me(): action.configure(text='Hello ' + name.get() + ' ' + number_chosen.get()) # Adding a Textbox Entry widget name = tk.StringVar() name_entered = ttk.Entry(mighty, width=12, textvariable=name)
tab1 = ttk.Frame(tabControl) # Create a tab tabControl.add(tab1, text='第一页') # Add the tab tab2 = ttk.Frame(tabControl) # Add a second tab tabControl.add(tab2, text='第二页') # Make second tab visible tab3 = ttk.Frame(tabControl) # Add a third tab tabControl.add(tab3, text='第三页') # Make second tab visible tabControl.pack(expand=1, fill="both") # Pack to make visible # ~ Tab Control introduced here ----------------------------------------- #---------------Tab1控件介绍------------------# # We are creating a container tab3 to hold all other widgets monty = ttk.LabelFrame(tab1, text='控件示范区1') monty.grid(column=0, row=0, padx=8, pady=4) # Modified Button Click Function def clickMe(): action.configure(text='Hello\n ' + name.get()) action.configure(state='disabled') # Disable the Button Widget # Changing our Label ttk.Label(monty, text="输入文字:").grid(column=0, row=0, sticky='W') # Adding a Textbox Entry widget name = tk.StringVar() nameEntered = ttk.Entry(monty, width=12, textvariable=name)
def find_func(event=None): ## find function def find(): word = find_input.get() text_editor.tag_remove('match', '1.0', tk.END) matches = 0 if word: start_pos = '1.0' while True: start_pos = text_editor.search(word, start_pos, stopindex=tk.END) if not start_pos: break end_pos = f'{start_pos} + {len(word)}c' text_editor.tag_add('match', start_pos, end_pos) matches += 1 start_pos = end_pos text_editor.tag_config('match', foreground='red', background='yellow') ## Replace Function def replace(): word = find_input.get() replace_text = replace_input.get() content = text_editor.get(1.0, tk.END) new_content = content.replace(word, replace_text) text_editor.delete(1.0, tk.END) text_editor.insert(1.0, new_content) find_dialogue = tk.Toplevel() find_dialogue.geometry('450x250+500+200') find_dialogue.title('Find and Replace') find_dialogue.resizable(0, 0) ## Frame find_frame = ttk.LabelFrame(find_dialogue, text='Find/Replace') find_frame.pack(pady=20) ## labels text_find_label = ttk.Label(find_frame, text='Find : ') text_replace_label = ttk.Label(find_frame, text="Replace : ") ## Entry find_input = ttk.Entry(find_frame, width=30) replace_input = ttk.Entry(find_frame, width=30) ## Button find_button = ttk.Button(find_frame, text='Find', command=find) replace_button = ttk.Button(find_frame, text='Replace', command=replace) ## label grid text_find_label.grid(row=0, column=0, padx=4, pady=4) text_replace_label.grid(row=1, column=0, padx=4, pady=4) ## Entry grid find_input.grid(row=0, column=1, padx=4, pady=4) replace_input.grid(row=1, column=1, padx=4, pady=4) ## button grid find_button.grid(row=2, column=0, padx=8, pady=4) replace_button.grid(row=2, column=1, padx=8, pady=4) find_dialogue.mainloop()
win.geometry("1360x768") tabControl = ttk.Frame(win) # Create Tab Control tab1 = ttk.Frame(tabControl) # Create a tab tab1.grid(column=0, row=0, sticky=tk.NW) # Add the tab tab2 = ttk.Frame(tabControl) # Create a tab tab2.grid(column=1, row=0, sticky=tk.NE) pageSettingTab = ttk.Frame(tabControl) # Create a tab pageSettingTab.grid(column=2, row=0, sticky=tk.NE) drawPanel = ttk.Frame(tabControl) # Create a tab drawPanel.grid(column=0, row=0, sticky=tk.NW) tabControl.pack(expand=1, fill="both") setPanel = ttk.Frame(tabControl) setPanel.grid(column=0, row=1, sticky=tk.SW) mighty = ttk.LabelFrame(tab1, text=' 任務預覽 ') mighty.grid(column=0, row=0) def ClickLabel(col, row): global nowSelectCol global nowSelectRow nowSelectCol = col nowSelectRow = row missionList = allMissionBigDict[nowBigPageNumber][nowSmallPageNumber] for x in range(CONSTEditorNumber): if x < 3: missionEditorDes[x]['text'] = str( missionList[nowSelectRow][nowSelectCol].Data[x]) missionEditorVar[x].set( missionList[nowSelectRow][nowSelectCol].Data[x])
def _create_properties(self): """Populate a frame with a list of all editable properties""" self._rcbag = {} # bag for row/column prop editors self._fgrid = f = ttk.Labelframe(self._sframe.innerframe, text=_('Grid options:'), padding=5) f.grid(sticky='nswe') # hack to resize correctly when properties are hidden label = ttk.Label(f) label.grid() label_tpl = "{0}:" row = 0 col = 0 groups = (('00', properties.GRID_PROPERTIES, properties.LAYOUT_OPTIONS), ) for gcode, plist, propdescr in groups: for name in plist: kwdata = propdescr[name] labeltext = label_tpl.format(name) label = ttk.Label(self._fgrid, text=labeltext, anchor=tk.W) label.grid(row=row, column=col, sticky=tk.EW, pady=2) widget = self._create_editor(self._fgrid, name, kwdata) widget.grid(row=row, column=col + 1, sticky=tk.EW, pady=2) row += 1 self._propbag[gcode + name] = (label, widget) # Grid row/col properties #labels gcode = '01' self._fgrc = fgrc = ttk.LabelFrame(self._sframe.innerframe, text=_('Grid row/column options:'), padding=5) fgrc.grid(row=1, column=0, sticky=tk.NSEW, pady='10 0') #hack to resize correctly when properties are hidden label = ttk.Label(fgrc) label.grid() row = col = 0 icol = 1 headers = [] for pname in properties.GRID_RC_PROPERTIES: label = ttk.Label(fgrc, text=pname) label.grid(row=row, column=icol) headers.append(label) icol += 1 self._internal = {'grc_headers': headers} # name_format = '{}_{}_{}' # {row/column}_{number}_{name} MAX_RC = 50 #rowconfig row += 1 trow_label = _('Row {0}:') tcol_label = _('Column {0}:') for index in range(0, MAX_RC): labeltext = trow_label.format(index) label = ttk.Label(fgrc, text=labeltext) label.grid(row=row, column=0) labeltext = tcol_label.format(index) labelc = ttk.Label(fgrc, text=labeltext) labelc.grid(row=row + MAX_RC, column=0, sticky=tk.E, pady=2) icol = 1 for pname in properties.GRID_RC_PROPERTIES: kwdata = properties.LAYOUT_OPTIONS[pname] alias = name_format.format('row', index, pname) widget = self._create_editor(fgrc, alias, kwdata) widget.grid(row=row, column=icol, pady=2, sticky='ew') self._rcbag[alias] = (label, widget) alias = name_format.format('column', index, pname) widget = self._create_editor(fgrc, alias, kwdata) widget.grid(row=row + MAX_RC, column=icol, pady=2, sticky='ew') self._rcbag[alias] = (labelc, widget) icol += 1 row += 1
def init_gen_tab(f): """Make widgets in the 'General' tab.""" def load_after_export(): """Read the 'After Export' radio set.""" AFTER_EXPORT_ACTION.set( GEN_OPTS.get_int('General', 'after_export_action', AFTER_EXPORT_ACTION.get())) def save_after_export(): """Save the 'After Export' radio set.""" GEN_OPTS['General']['after_export_action'] = str( AFTER_EXPORT_ACTION.get()) after_export_frame = ttk.LabelFrame( f, text=_('After Export:'), ) after_export_frame.grid( row=0, rowspan=2, column=0, sticky='NS', padx=(0, 10), ) VARS['General', 'after_export_action'] = AFTER_EXPORT_ACTION AFTER_EXPORT_ACTION.load = load_after_export AFTER_EXPORT_ACTION.save = save_after_export load_after_export() exp_nothing = ttk.Radiobutton( after_export_frame, text=_('Do Nothing'), variable=AFTER_EXPORT_ACTION, value=AfterExport.NORMAL.value, ) exp_minimise = ttk.Radiobutton( after_export_frame, text=_('Minimise BEE2'), variable=AFTER_EXPORT_ACTION, value=AfterExport.MINIMISE.value, ) exp_quit = ttk.Radiobutton( after_export_frame, text=_('Quit BEE2'), variable=AFTER_EXPORT_ACTION, value=AfterExport.QUIT.value, ) exp_nothing.grid(row=0, column=0, sticky='w') exp_minimise.grid(row=1, column=0, sticky='w') exp_quit.grid(row=2, column=0, sticky='w') add_tooltip(exp_nothing, _('After exports, do nothing and ' 'keep the BEE2 in focus.')) add_tooltip(exp_minimise, _('After exports, minimise to the taskbar/dock.')) add_tooltip(exp_minimise, _('After exports, quit the BEE2.')) UI['launch_game'] = launch_game = make_checkbox( after_export_frame, section='General', item='launch_Game', var=LAUNCH_AFTER_EXPORT, desc=_('Launch Game'), tooltip=_('After exporting, launch the selected game automatically.'), ) launch_game.grid(row=3, column=0, sticky='W', pady=(10, 0)) if sound.initiallised: UI['mute'] = mute = make_checkbox( f, section='General', item='play_sounds', desc=_('Play Sounds'), var=PLAY_SOUND, ) else: UI['mute'] = mute = ttk.Checkbutton( f, text=_('Play Sounds'), state='disabled', ) add_tooltip( UI['mute'], _('Pyglet is either not installed or broken.\n' 'Sound effects have been disabled.')) mute.grid(row=0, column=1, sticky='E') UI['reset_cache'] = reset_cache = ttk.Button( f, text=_('Reset Package Caches'), command=clear_caches, ) reset_cache.grid(row=1, column=1, sticky='EW') add_tooltip( reset_cache, _('Force re-extracting all package resources. This requires a restart.' ), )
text_ctrler.insert(tkinter.END, valid_invoice.getInvoiceCode()) text_ctrler.insert(tkinter.END, '\t') text_ctrler.insert(tkinter.END, valid_invoice.getInvoiceNo()) text_ctrler.insert(tkinter.END, '\t') text_ctrler.insert(tkinter.END, '-'.join(valid_invoice.getDate())) text_ctrler.insert(tkinter.END, '\t') text_ctrler.insert(tkinter.END, valid_invoice.getCheckcode()[-6:]) text_ctrler.insert(tkinter.END, '\n') text_ctrler.update() win = tkinter.Tk() win.title("汽油发票助手") win.resizable(False, False) invoices_pdf_dir_path_lf = ttk.LabelFrame(win, text='汽油电子发票') invoices_pdf_dir_path_lf.grid(row=0, column=0, pady=4) invoices_pdf_dir_path_label = ttk.Label(invoices_pdf_dir_path_lf, text='PDF 目录:') invoices_pdf_dir_path_label.grid(column=0, row=0, sticky='W') invoices_pdf_dir_path_sv = tkinter.StringVar() tkinter.Entry(invoices_pdf_dir_path_lf, width=40, textvariable=invoices_pdf_dir_path_sv).grid(row=0, column=1, padx=6) tkinter.Button( invoices_pdf_dir_path_lf, text='选择', command=lambda: invoices_pdf_dir_path_sv.set(askdirectory())).grid( row=0, column=2)
from tkinter import * from tkinter import ttk sushiGUI=Tk() sushiGUI.title('Place order') Menuframe=ttk.LabelFrame(sushiGUI,text='Menu') Menuframe.grid(row=1,column=1) mylist=['Appetizer','Entree','Pizza','Sashimi','Soup','Desert'] mylist2=StringVar(value=mylist) foodlist=Listbox(Menuframe,listvariable=mylist2) foodlist.grid(row=1,column=1) sushiGUI.mainloop()
# make its parent the frame created. # configure the text of the button to say "click me" # use the grid geometry manager here instead of the pack manager. # configured the top level root window to use the pack manager # by using it on the frame, # By using the grid geometry manager on this widget # I'm adding to the frame, any other widgets I add to the frame later # will also need to be done so by using the grid geometry manager. ttk.Button(frame, text='Click Me').grid() # add padding to my frame to create a buffer around the button on the inside of the frame by configuring the padding property. # Padding accepts a list of two values: # the number of pixels in the X direction and # the number of pixels in the Y direction of padding to add around that frame. # a frame with # 30 pixels padding on the inside in the X direction # 15 pixels of padding in the Y direction. frame.config(padding=(30, 15)) # the label frame. # create a label frame using the Ttk label frame constructor method # both the L and F are capitalized in label frame. # make the top level root window the parent for this frame. # properties # height and width # text property ttk.LabelFrame(root, height=100, width=200, text='My Frame').pack() root.mainloop()
# Radiobutton callback def radCall(): radSel = radVar.get() if radSel == 0: win.configure(background=colors[0]) elif radSel == 1: win.configure(background=colors[1]) elif radSel == 2: win.configure(background=colors[2]) radVar = tk.IntVar() radVar.set(99) # Creating 3 radio buttons in a loop for col in range(3): curRad = tk.Radiobutton(win, text=colors[col], variable=radVar, value=col, command=radCall) curRad.grid(column=col, row=6, sticky=tk.W) # Create a container to hold Labels labelsFrame = ttk.LabelFrame(win, text=" Labels in a Frame ") labelsFrame.grid(column=0, row=7) # Place Labels into the container element ttk.Label(labelsFrame, text="Label1").grid(column=0, row=0, sticky=tk.W) ttk.Label(labelsFrame, text="Label2").grid(column=1, row=0, sticky=tk.W) ttk.Label(labelsFrame, text="Label3").grid(column=2, row=0, sticky=tk.W) nameEntered.focus() win.mainloop()
def __init__(self, master, moodlights): self.moodlights = moodlights self.master = master master.title("RPi RGB") master.geometry("800x800") self.notebook = ttk.Notebook(master) self.notebook.enable_traversal() self.notebook.pack(fill="both", expand=1) color_wipe_notebook_frame = ttk.Frame(self.notebook, width=800, height=600) pulse_notebook_frame = ttk.Frame(self.notebook, width=800, height=600) wave_notebook_frame = ttk.Frame(self.notebook, width=800, height=600) rainbow_cycle_notebook_frame = ttk.Frame(self.notebook, width=800, height=600) rainbow_chase_notebook_frame = ttk.Frame(self.notebook, width=800, height=600) construct_notebook_frame = ttk.Frame(self.notebook, width=800, height=600) color_wipe_frame = self.create_canvas(color_wipe_notebook_frame) pulse_frame = self.create_canvas(pulse_notebook_frame) wave_frame = self.create_canvas(wave_notebook_frame) rainbow_cycle_frame = self.create_canvas(rainbow_cycle_notebook_frame) rainbow_chase_frame = self.create_canvas(rainbow_chase_notebook_frame) construct_frame = self.create_canvas(construct_notebook_frame) # Set up color wipe frame color_wipe_sequence = [] self.setup_pick_colors(color_wipe_frame, color_wipe_sequence) color_wipe_params_frame = ttk.LabelFrame(color_wipe_frame, text="Parameters", padding=20) color_wipe_iterations = self.setup_entry(color_wipe_params_frame, "Num iterations (0 is infinite): ") color_wipe_wait_ms = self.setup_entry(color_wipe_params_frame, "Wait time (ms): ") color_wipe_params_frame.pack(pady=10) color_wipe_button = ttk.Button(color_wipe_frame, text="Display", width="20", command=lambda: self.color_wipe(color_wipe_sequence, color_wipe_iterations.get(), color_wipe_wait_ms.get())) color_wipe_button.pack(pady=20) constructed_sequence = [] constructed_sequence_frame = ttk.LabelFrame(construct_frame, text="Constructed Sequence") color_wipe_construct_button = ttk.Button(color_wipe_frame, text="Add to Construction", width="20", command=lambda: self.add_construction(constructed_sequence_frame, constructed_sequence, { 'pattern': 'color_wipe', 'color_sequence': color_wipe_sequence, 'iterations': color_wipe_iterations.get(), 'wait_ms': color_wipe_wait_ms.get() })) color_wipe_construct_button.pack(pady=5) # Set up pulse frame pulse_params_frame = ttk.LabelFrame(pulse_frame, text="Parameters", padding=20) pulse_iterations = self.setup_entry(pulse_params_frame, "Num iterations (0 is infinite): ") pulse_wait_ms = self.setup_entry(pulse_params_frame, "Wait time (ms): ") pulse_params_frame.pack(pady=70) pulse_button = ttk.Button(pulse_frame, text="Display", width="20", command=lambda: self.pulse(pulse_iterations.get(), pulse_wait_ms.get())) pulse_button.pack(pady=20) pulse_construct_button = ttk.Button(pulse_frame, text="Add to Construction", width="20", command=lambda: self.add_construction(constructed_sequence_frame, constructed_sequence, { 'pattern': 'pulse', 'iterations': pulse_iterations.get(), 'wait_ms': pulse_wait_ms.get() })) pulse_construct_button.pack(pady=5) # Set up wave frame wave_sequence = [] self.setup_pick_colors(wave_frame, wave_sequence) wave_params_frame = ttk.LabelFrame(wave_frame, text="Parameters", padding=10) wave_iterations = self.setup_entry(wave_params_frame, "Num iterations (0 is infinite): ") wave_intensity = self.setup_entry(wave_params_frame, "Intensity (0-255): ") wave_wait_ms = self.setup_entry(wave_params_frame, "Wait time (ms): ") wave_spread = self.setup_entry(wave_params_frame, "Spread: ") wave_is_reverse = self.setup_entry(wave_params_frame, "Is reverse (True or False): ") wave_params_frame.pack(pady=0) wave_button = ttk.Button(wave_frame, text="Display", width="20", command=lambda: self.wave(wave_sequence, wave_iterations.get(), wave_intensity.get(), wave_wait_ms.get(), wave_spread.get(), wave_is_reverse.get())) wave_button.pack(pady=10) wave_construct_button = ttk.Button(wave_frame, text="Add to Construction", width="20", command=lambda: self.add_construction(constructed_sequence_frame, constructed_sequence, { 'pattern': 'wave', 'color_sequence': wave_sequence, 'iterations': wave_iterations.get(), 'intensity': wave_intensity.get(), 'wait_ms': wave_wait_ms.get(), 'spread': wave_spread.get(), 'is_reverse': wave_is_reverse.get() })) wave_construct_button.pack(pady=5) # Set up rainbow cycle frame rainbow_cycle_params_frame = ttk.LabelFrame(rainbow_cycle_frame, text="Parameters", padding=20) rainbow_cycle_iterations = self.setup_entry(rainbow_cycle_params_frame, "Num iterations (0 is infinite): ") rainbow_cycle_wait_ms = self.setup_entry(rainbow_cycle_params_frame, "Wait time (ms): ") rainbow_cycle_params_frame.pack(pady=70) rainbow_cycle_button = ttk.Button(rainbow_cycle_frame, text="Display", width="20", command=lambda: self.rainbow_cycle(rainbow_cycle_iterations.get(), rainbow_cycle_wait_ms.get())) rainbow_cycle_button.pack(pady=20) rainbow_cycle_construct_button = ttk.Button(rainbow_cycle_frame, text="Add to Construction", width="20", command=lambda: self.add_construction(constructed_sequence_frame, constructed_sequence, { 'pattern': 'rainbow_cycle', 'iterations': rainbow_cycle_iterations.get(), 'wait_ms': rainbow_cycle_wait_ms.get() })) rainbow_cycle_construct_button.pack(pady=5) # Set up rainbow chase frame rainbow_chase_params_frame = ttk.LabelFrame(rainbow_chase_frame, text="Parameters", padding=20) rainbow_chase_iterations = self.setup_entry(rainbow_chase_params_frame, "Num iterations (0 is infinite): ") rainbow_chase_wait_ms = self.setup_entry(rainbow_chase_params_frame, "Wait time (ms): ") rainbow_chase_params_frame.pack(pady=70) rainbow_chase_button = ttk.Button(rainbow_chase_frame, text="Display", width="20", command=lambda: self.rainbow_chase(rainbow_chase_iterations.get(), rainbow_chase_wait_ms.get())) rainbow_chase_button.pack(pady=20) rainbow_chase_construct_button = ttk.Button(rainbow_chase_frame, text="Add to Construction", width="20", command=lambda: self.add_construction(constructed_sequence_frame, constructed_sequence, { 'pattern': 'rainbow_chase', 'iterations': rainbow_chase_iterations.get(), 'wait_ms': rainbow_chase_wait_ms.get() })) rainbow_chase_construct_button.pack(pady=5) constructed_sequence_frame.pack(pady=10) constructed_iterations = self.setup_entry(construct_frame, "Num iterations (0 is infinite): ") constructed_button = ttk.Button(construct_frame, text="Display", width="20", command=lambda: self.display_construction(constructed_sequence, constructed_iterations.get())) constructed_button.pack(pady=30) color_wipe_notebook_frame.pack(fill="both", expand=1) pulse_notebook_frame.pack(fill="both", expand=1) wave_notebook_frame.pack(fill="both", expand=1) rainbow_cycle_notebook_frame.pack(fill="both", expand=1) rainbow_chase_notebook_frame.pack(fill="both", expand=1) construct_notebook_frame.pack(fill="both", expand=1) self.notebook.add(color_wipe_notebook_frame, text="Color Wipe") self.notebook.add(pulse_notebook_frame, text="Pulse") self.notebook.add(wave_notebook_frame, text="Wave") self.notebook.add(rainbow_cycle_notebook_frame, text="Rainbow Cycle") self.notebook.add(rainbow_chase_notebook_frame, text="Rainbow Chase") self.notebook.add(construct_notebook_frame, text="Construct")
mail = tk.StringVar() mail_entered = ttk.Entry(mighty, width=30, textvariable=mail) mail_entered.grid(column=1, row=1, sticky=tk.W, padx=5, pady=5) mail_entered.focus() create_ToolTip(mail_entered, 'Contact mail') a_lable = ttk.Label(mighty, text='Telephone:') a_lable.grid(column=1, row=2, sticky=tk.W, padx=5, pady=5) a_lable.configure(background='ivory', font=('Comic Sans MS', '12', 'normal')) tel = tk.StringVar() tel_entered = ttk.Entry(mighty, width=30, textvariable=tel) tel_entered.grid(column=1, row=3, sticky=tk.W, padx=5, pady=5) tel_entered.focus() create_ToolTip(tel_entered, 'Contact telephone') list_frame = ttk.LabelFrame(mighty) list_frame.grid(column=0, row=4, padx=8, pady=8, columnspan=2) List = tk.Listbox(list_frame, height=20, width=70) List.grid(row=8, column=0, columnspan=2) scr = tk.Scrollbar(list_frame) scr.grid(row=8, column=2, rowspan=12) List.configure(yscrollcommand=scr.set) scr.configure(command=List.yview) List.bind('<<ListboxSelect>>', get_selected_row) buttons_frame = tk.Frame(mighty) buttons_frame.grid(column=0, row=15, columnspan=2, sticky=tk.W) buttons_frame.configure(background='ivory') tk.Button(buttons_frame, text='View all',
def create_widgets(self): tabControl = ttk.Notebook(self.win) # Create Tab Control tab1 = ttk.Frame(tabControl) # Create a tab tabControl.add(tab1, text='Tab 1') # Add the tab tab2 = ttk.Frame(tabControl) # Add a second tab tabControl.add(tab2, text='Tab 2') # Make second tab visible tabControl.pack(expand=1, fill="both") # Pack to make visible # LabelFrame using tab1 as the parent mighty = ttk.LabelFrame(tab1, text=' Mighty Python ') mighty.grid(column=0, row=0, padx=8, pady=4) # Modify adding a Label using mighty as the parent instead of win a_label = ttk.Label(mighty, text="Enter a name:") a_label.grid(column=0, row=0, sticky='W') # Adding a Textbox Entry widget self.name = tk.StringVar() self.name_entered = ttk.Entry(mighty, width=24, textvariable=self.name) self.name_entered.grid(column=0, row=1, sticky='W') # Adding a Button self.action = ttk.Button(mighty, text="Click Me!", command=self.click_me) self.action.grid(column=2, row=1) ttk.Label(mighty, text="Choose a number:").grid(column=1, row=0) number = tk.StringVar() self.number_chosen = ttk.Combobox(mighty, width=14, textvariable=number, state='readonly') self.number_chosen['values'] = (1, 2, 4, 42, 100) self.number_chosen.grid(column=1, row=1) self.number_chosen.current(0) # Adding a Spinbox widget self.spin = Spinbox(mighty, values=(1, 2, 4, 42, 100), width=5, bd=9, command=self._spin) # using range self.spin.grid(column=0, row=2, sticky='W') # align left # Using a scrolled Text control scrol_w = 40; scrol_h = 10 # increase sizes self.scrol = scrolledtext.ScrolledText(mighty, width=scrol_w, height=scrol_h, wrap=tk.WORD) self.scrol.grid(column=0, row=3, sticky='WE', columnspan=3) for child in mighty.winfo_children(): # add spacing to align widgets within tabs child.grid_configure(padx=4, pady=2) #===================================================================================== # Tab Control 2 ---------------------------------------------------------------------- self.mighty2 = ttk.LabelFrame(tab2, text=' The Snake ') self.mighty2.grid(column=0, row=0, padx=8, pady=4) # Creating three checkbuttons chVarDis = tk.IntVar() check1 = tk.Checkbutton(self.mighty2, text="Disabled", variable=chVarDis, state='disabled') check1.select() check1.grid(column=0, row=0, sticky=tk.W) chVarUn = tk.IntVar() check2 = tk.Checkbutton(self.mighty2, text="UnChecked", variable=chVarUn) check2.deselect() check2.grid(column=1, row=0, sticky=tk.W) chVarEn = tk.IntVar() check3 = tk.Checkbutton(self.mighty2, text="Enabled", variable=chVarEn) check3.deselect() check3.grid(column=2, row=0, sticky=tk.W) # trace the state of the two checkbuttons chVarUn.trace('w', lambda unused0, unused1, unused2 : self.checkCallback()) chVarEn.trace('w', lambda unused0, unused1, unused2 : self.checkCallback()) # First, we change our Radiobutton global variables into a list colors = ["Blue", "Gold", "Red"] # create three Radiobuttons using one variable self.radVar = tk.IntVar() # Next we are selecting a non-existing index value for radVar self.radVar.set(99) # Now we are creating all three Radiobutton widgets within one loop for col in range(3): curRad = tk.Radiobutton(self.mighty2, text=colors[col], variable=self.radVar, value=col, command=self.radCall) curRad.grid(column=col, row=1, sticky=tk.W) # row=6 # And now adding tooltips tt.create_ToolTip(curRad, 'This is a Radiobutton control') # Add a Progressbar to Tab 2 self.progress_bar = ttk.Progressbar(tab2, orient='horizontal', length=286, mode='determinate') self.progress_bar.grid(column=0, row=3, pady=2) # Create a container to hold buttons buttons_frame = ttk.LabelFrame(self.mighty2, text=' ProgressBar ') buttons_frame.grid(column=0, row=2, sticky='W', columnspan=2) # Add Buttons for Progressbar commands ttk.Button(buttons_frame, text=" Run Progressbar ", command=self.run_progressbar).grid(column=0, row=0, sticky='W') ttk.Button(buttons_frame, text=" Start Progressbar ", command=self.start_progressbar).grid(column=0, row=1, sticky='W') ttk.Button(buttons_frame, text=" Stop immediately ", command=self.stop_progressbar).grid(column=0, row=2, sticky='W') ttk.Button(buttons_frame, text=" Stop after second ", command=self.progressbar_stop_after).grid(column=0, row=3, sticky='W') for child in buttons_frame.winfo_children(): child.grid_configure(padx=2, pady=2) for child in self.mighty2.winfo_children(): child.grid_configure(padx=8, pady=2) # Creating a Menu Bar menu_bar = Menu(self.win) self.win.config(menu=menu_bar) # Add menu items file_menu = Menu(menu_bar, tearoff=0) file_menu.add_command(label="New") file_menu.add_separator() file_menu.add_command(label="Exit", command=self._quit) menu_bar.add_cascade(label="File", menu=file_menu) # Display a Message Box def _msgBox(): msg.showinfo('Python Message Info Box', 'A Python GUI created using tkinter:\nThe year is 2017.') # Add another Menu to the Menu Bar and an item help_menu = Menu(menu_bar, tearoff=0) help_menu.add_command(label="About", command=_msgBox) # display messagebox when clicked menu_bar.add_cascade(label="Help", menu=help_menu) # Change the main windows icon self.win.iconbitmap('pyc.ico') # It is not necessary to create a tk.StringVar() # strData = tk.StringVar() strData = self.spin.get() # call function self.usingGlobal() self.name_entered.focus() # Add Tooltips ----------------------------------------------------- # Add a Tooltip to the Spinbox tt.create_ToolTip(self.spin, 'This is a Spinbox control') # Add Tooltips to more widgets tt.create_ToolTip(self.name_entered, 'This is an Entry control') tt.create_ToolTip(self.action, 'This is a Button control') tt.create_ToolTip(self.scrol, 'This is a ScrolledText control')
cmbChosenUp.grid(column = 1, row = 0) cmbChosenUp.current(0) DOWN= tk.StringVar()#增加down下拉菜单 cmbChosenDown = ttk.Combobox(frameUpDown,width=8, height=10,textvariable =DOWN) cmbChosenDown['value']=('点动','自锁') cmbChosenDown.grid(column = 1, row = 1,padx=10,pady=7) cmbChosenDown.current(0) UpDown= tk.StringVar()#增加上下关系下拉菜单 cmbChosenUpDown = ttk.Combobox(frameUpDown,width=8, height=10,textvariable =UpDown) cmbChosenUpDown['value']=('相互拟制','不拟制') cmbChosenUpDown.grid(column = 50, row = 1,padx=30,pady=7) cmbChosenUpDown.current(0) #增加frame******************东西 frameEW = ttk.LabelFrame(win,text = "东西键功能设定", width=300, height=80) frameEW.grid(row=1, column=0, sticky=W,padx=10,pady=7) ttk.Label(frameEW,text="东西关系").grid(column=50,row=1)#增加东西关系标签 ttk.Label(frameEW,text="东EAST").grid(sticky = W,column=0,row=1)#增加东标签 ttk.Label(frameEW,text="西WEST").grid(sticky = W,column=0,row=2)#增加西WEST标签 EAST= tk.StringVar()#增加EAST下拉菜单 cmbChosenEAST = ttk.Combobox(frameEW,width=8, height=10,textvariable = EAST) cmbChosenEAST['value']=('点动','自锁') cmbChosenEAST.grid(column = 1, row = 1,padx=17) cmbChosenEAST.current(0) WEST= tk.StringVar()#增加WEST下拉菜单 cmbChosenWEST = ttk.Combobox(frameEW,width=8, height=10,textvariable = WEST) cmbChosenWEST['value']=('点动','自锁') cmbChosenWEST.grid(column = 1, row =2,padx=10,pady=7) cmbChosenWEST.current(0) EAST_WEST= tk.StringVar()
("Image 3", 2), ("Image 4", 3), ("Image 5", 4), ] for (Txt, Val) in RadioButtonList: tk.Radiobutton( Frame2, text=Txt, value=Val, variable=RadioButtonVar, command=lambda: ChangeImage(RadioButtonVar.get())).pack(anchor=tk.W) TestLabel2 = tk.Label(Frame2, textvariable=RadioButtonVar).pack() # Ramka 3 - radiobuttony z TTK dodawane pojedynczo Frame3 = ttk.LabelFrame(Root, text="Radio Buttony TTK") Frame3.grid(row=0, column=5, sticky=tk.N) ttk.Radiobutton( Frame3, text="Foto 1", value=0, variable=RadioButtonVar, command=lambda: ChangeImage(RadioButtonVar.get())).pack(anchor=tk.W) ttk.Radiobutton( Frame3, text="Foto 2", value=1, variable=RadioButtonVar, command=lambda: ChangeImage(RadioButtonVar.get())).pack(anchor=tk.W) ttk.Radiobutton(
win.title("GST Calculator") win.geometry("400x300") win.minsize(400,300) win.maxsize(400,300) menubar = tk.Menu(win) def onTouch(): webbrowser.open_new_tab(r'http://vaibhavpathak.diagodevelopers.dx.am/') filemenu = tk.Menu(menubar, tearoff=0) filemenu.add_command(label="About Developer", command = onTouch) menubar.add_cascade(label="Help", menu=filemenu) win.config(menu=menubar) label_frame = ttk.LabelFrame(win, width=70) label_frame.grid(row=0,column=0,padx=55,pady=70) gst_label = ttk.Label(label_frame, text="Enter Your Amount : ") gst_label.grid(row=0,column=0,padx=0,pady=3,sticky=tk.W) gst_persent = ttk.Label(label_frame, text="Select Your GST Percent (%) : ") gst_persent.grid(row=1, column=0,sticky=tk.W) gst_amount = tk.StringVar() gst_entry = ttk.Entry(label_frame, width=20, textvariable=gst_amount) gst_entry.grid(row=0,column=1,padx=0, pady=5) gst_entry.focus() get_percentcomo = ttk.Combobox(label_frame, width=17,state='readonly') get_percentcomo.grid(row=1,column=1) get_percentcomo['values'] = (5,12,18,28) get_percentcomo.current(0) def onClick(): user_amount = gst_amount.get()
def __init__(self, master, configure): self.master = master self.width = master.winfo_width() self.height = master.winfo_height() self.configure = configure self.master.title(self.configure.window_title + ' ' + str(lybconstant.LYB_VERSION)) self.option_dic = {} self.gui_style = ttk.Style() self.shake_count = 0 self.lyblicense = likeyoubot_license.LYBLicense() self.progress_bar = None self.num_of_file = 0 self.rest = None self.worker_thread = None self.waiting_queue = None self.download_label = None self.download_file_label = None self.logger = likeyoubot_logger.LYBLogger.getLogger() self.logger.debug(self.gui_style.theme_names()) self.gui_style.theme_use('vista') self.gui_style.configure('.', font=lybconstant.LYB_FONT) self.gui_style.configure("Tab", focuscolor=self.gui_style.configure(".")["background"]) self.gui_style.configure("TButton", focuscolor=self.gui_style.configure(".")["background"]) self.gui_style.configure("TCheckbutton", focuscolor=self.gui_style.configure(".")["background"]) self.main_frame = ttk.Frame(master) label_frame = ttk.LabelFrame(self.main_frame, text='로그인') frame_extra = ttk.Frame(label_frame) frame_extra.pack(pady=5) frame_top = ttk.Frame(label_frame) frame_left = ttk.Frame(frame_top) frame = ttk.Frame(frame_left) label = ttk.Label( master=frame, text="계정", justify=tkinter.LEFT, width=10 ) label.pack(side=tkinter.LEFT) if not lybconstant.LYB_DO_BOOLEAN_SAVE_LOGIN_ACCOUNT in self.configure.common_config: self.configure.common_config[lybconstant.LYB_DO_BOOLEAN_SAVE_LOGIN_ACCOUNT] = False if not self.configure.common_config[lybconstant.LYB_DO_BOOLEAN_SAVE_LOGIN_ACCOUNT]: self.configure.common_config[lybconstant.LYB_DO_BOOLEAN_SAVE_LOGIN_ACCOUNT + '_id'] = '' self.configure.common_config[lybconstant.LYB_DO_BOOLEAN_SAVE_LOGIN_ACCOUNT + '_passwd'] = '' self.option_dic[lybconstant.LYB_DO_BOOLEAN_SAVE_LOGIN_ACCOUNT + '_id'] = tkinter.StringVar(frame) if not lybconstant.LYB_DO_BOOLEAN_SAVE_LOGIN_ACCOUNT + '_id' in self.configure.common_config: self.configure.common_config[lybconstant.LYB_DO_BOOLEAN_SAVE_LOGIN_ACCOUNT + '_id'] = '' self.option_dic[lybconstant.LYB_DO_BOOLEAN_SAVE_LOGIN_ACCOUNT + '_id'].set( self.configure.common_config[lybconstant.LYB_DO_BOOLEAN_SAVE_LOGIN_ACCOUNT + '_id']) entry = ttk.Entry( master=frame, textvariable=self.option_dic[lybconstant.LYB_DO_BOOLEAN_SAVE_LOGIN_ACCOUNT + '_id'], width=24 ) entry.pack(side=tkinter.LEFT, padx=2) entry.focus() frame.pack() frame = ttk.Frame(frame_left) label = ttk.Label( master=frame, text="비밀번호", justify=tkinter.LEFT, width=10 ) label.pack(side=tkinter.LEFT) self.option_dic[lybconstant.LYB_DO_BOOLEAN_SAVE_LOGIN_ACCOUNT + '_passwd'] = tkinter.StringVar(frame) if not lybconstant.LYB_DO_BOOLEAN_SAVE_LOGIN_ACCOUNT + '_passwd' in self.configure.common_config: self.configure.common_config[lybconstant.LYB_DO_BOOLEAN_SAVE_LOGIN_ACCOUNT + '_passwd'] = '' self.option_dic[lybconstant.LYB_DO_BOOLEAN_SAVE_LOGIN_ACCOUNT + '_passwd'].set('') else: self.option_dic[lybconstant.LYB_DO_BOOLEAN_SAVE_LOGIN_ACCOUNT + '_passwd'].set( self.lyblicense.get_decrypt( self.configure.common_config[lybconstant.LYB_DO_BOOLEAN_SAVE_LOGIN_ACCOUNT + '_passwd']) ) entry = ttk.Entry( master=frame, textvariable=self.option_dic[lybconstant.LYB_DO_BOOLEAN_SAVE_LOGIN_ACCOUNT + '_passwd'], show="*", width=24 ) entry.pack(side=tkinter.LEFT, padx=2) frame.pack() frame_left.pack(anchor=tkinter.W, side=tkinter.LEFT) frame_extra = ttk.Frame(frame_top) frame_extra.pack(side=tkinter.LEFT, padx=1) frame_right = ttk.Frame(frame_top) button = ttk.Button( master=frame_right, text="로그인", command=lambda: self.callback_login_button(None) ) button.pack(fill=tkinter.BOTH, expand=True) frame_right.pack(fill=tkinter.BOTH, expand=True) frame_top.pack() if not lybconstant.LYB_DO_BOOLEAN_SAVE_LOGIN_ACCOUNT + '_chat_id' in self.configure.common_config: self.configure.common_config[lybconstant.LYB_DO_BOOLEAN_SAVE_LOGIN_ACCOUNT + '_chat_id'] = '' self.option_dic[lybconstant.LYB_DO_BOOLEAN_SAVE_LOGIN_ACCOUNT] = tkinter.BooleanVar() self.option_dic[lybconstant.LYB_DO_BOOLEAN_SAVE_LOGIN_ACCOUNT].trace( 'w', lambda *args: self.callback_save_login_account_booleanvar(args, lybconstant.LYB_DO_BOOLEAN_SAVE_LOGIN_ACCOUNT) ) self.option_dic[lybconstant.LYB_DO_BOOLEAN_SAVE_LOGIN_ACCOUNT].set( self.configure.common_config[lybconstant.LYB_DO_BOOLEAN_SAVE_LOGIN_ACCOUNT]) frame_bottom = ttk.Frame(label_frame) frame = ttk.Frame(frame_bottom) check_box = ttk.Checkbutton( master=frame_bottom, text='아이디/비밀번호 기억하기', variable=self.option_dic[lybconstant.LYB_DO_BOOLEAN_SAVE_LOGIN_ACCOUNT], onvalue=True, offvalue=False ) check_box.pack(anchor=tkinter.E) frame.pack(anchor=tkinter.E) # frame = ttk.Frame(frame_bottom) if not lybconstant.LYB_DO_BOOLEAN_AUTO_UPDATE in self.configure.common_config: self.configure.common_config[lybconstant.LYB_DO_BOOLEAN_AUTO_UPDATE] = False self.option_dic[lybconstant.LYB_DO_BOOLEAN_AUTO_UPDATE] = tkinter.BooleanVar() self.option_dic[lybconstant.LYB_DO_BOOLEAN_AUTO_UPDATE].trace( 'w', lambda *args: self.callback_auto_update_booleanvar(args, lybconstant.LYB_DO_BOOLEAN_AUTO_UPDATE) ) self.option_dic[lybconstant.LYB_DO_BOOLEAN_AUTO_UPDATE].set( self.configure.common_config[lybconstant.LYB_DO_BOOLEAN_AUTO_UPDATE]) check_box = ttk.Checkbutton( master=frame_bottom, text='자동 업데이트', variable=self.option_dic[lybconstant.LYB_DO_BOOLEAN_AUTO_UPDATE], onvalue=True, offvalue=False ) # check_box.pack(anchor=tkinter.E) # frame.pack(anchor=tkinter.E) frame_extra = ttk.Frame(frame_bottom) frame_extra.pack(pady=1) s = ttk.Style() s.configure('label_link.TLabel', foreground='blue', font=('굴림체', 9, 'underline')) link_url = "회원가입" frame = ttk.Frame(frame_bottom) label = ttk.Label( master=frame, text=link_url, justify=tkinter.LEFT, style='label_link.TLabel', cursor='hand2' ) label.pack(side=tkinter.LEFT) label.bind("<Button-1>", self.callback_register) frame.pack(anchor=tkinter.E) frame_bottom.pack(fill=tkinter.X, pady=5) label_frame.pack(padx=5, pady=10) frame_extra = ttk.Frame(frame_bottom) frame_extra.pack(pady=1) link_url = "아이디 비밀번호 찾기" frame = ttk.Frame(frame_bottom) label = ttk.Label( master=frame, text=link_url, justify=tkinter.LEFT, style='label_link.TLabel', cursor='hand2' ) label.pack(side=tkinter.LEFT) label.bind("<Button-1>", self.callback_password_lost) frame.pack(anchor=tkinter.E) frame_bottom.pack(fill=tkinter.X, pady=5) label_frame.pack(padx=5, pady=10) frame_message = ttk.Frame(self.main_frame) s = ttk.Style() s.configure('label_error.TLabel', foreground='red', font=('굴림체', 9)) frame = ttk.Frame(frame_message) self.option_dic[lybconstant.LYB_DO_STRING_LOGIN_MESSAGE] = tkinter.StringVar(frame) self.option_dic[lybconstant.LYB_DO_STRING_LOGIN_MESSAGE].set('') label = ttk.Label( master=frame, textvariable=self.option_dic[lybconstant.LYB_DO_STRING_LOGIN_MESSAGE], justify=tkinter.LEFT, wraplength=320, style='label_error.TLabel' ) label.pack(side=tkinter.LEFT) frame.pack(anchor=tkinter.W) frame_message.pack(anchor=tkinter.W, padx=5, pady=5) self.main_frame.pack(fill=tkinter.BOTH, expand=True) self.master.bind('<Return>', self.callback_login_button)
p1 = ttk.Frame(nb) p2 = ttk.Frame(nb) nb.add(p1, text='GUI') nb.add(p2, text='Details') nb.pack(expand=True, fill='both') IMAGE_PATHp1 = r"C:\Users\91735\Downloads\image.png" WIDTHp1, HEIGTHp1 = 1550, 800 canvasp1 = tk.Canvas(p1, width=WIDTHp1, height=HEIGTHp1) canvasp1.grid(row=0, column=0) imgp1 = ImageTk.PhotoImage( Image.open(IMAGE_PATHp1).resize((WIDTHp1, HEIGTHp1), Image.ANTIALIAS)) canvasp1.background = imgp1 bgp1 = canvasp1.create_image(0, 0, anchor=tk.NW, image=imgp1) win = ttk.LabelFrame(p1) #.grid(row=50, column = 10,) win.place(relx=0.5, rely=0.5, anchor='center') IMAGE_PATHwin = r"C:\Users\91735\Downloads\441387-gorgerous-dark-blue-background-images-1920x1080-for-android-50.jpg" WIDTHwin, HEIGTHwin = 1000, 500 canvaswin = tk.Canvas(win, width=WIDTHwin, height=HEIGTHwin) canvaswin.place(relx=0.5, rely=0.5, anchor='center') imgwin = ImageTk.PhotoImage( Image.open(IMAGE_PATHwin).resize((WIDTHwin, HEIGTHwin), Image.ANTIALIAS)) canvaswin.background = imgwin # Keep a reference in case this code is put in a function. bgwin = canvaswin.create_image(0, 0, anchor=tk.NW, image=imgwin) title = ttk.LabelFrame(p1) title.place(relx=0.5, rely=0.25, anchor='n') IMAGE_PATHtitle = r"C:\Users\91735\Downloads\441387-gorgerous-dark-blue-background-images-1920x1080-for-android-50.jpg" WIDTHtitle, HEIGTHtitle = 1000, 500
import tkinter as tk from tkinter import ttk #has adv widgets from tkinter import scrolledtext from tkinter import Menu #create instance win = tk.Tk() #add a title win.title("Python GUI") #creating a container frame to hold all other widgets monty = ttk.LabelFrame(win, text=' Monty Python') monty.grid(column=0, row=0) #grid manager, modify adding a Label #aLabel = ttk.Label(monty, text=" ") #aLabel.grid(column=0, row=0) #Button Click Event Function def clickMe(): action.configure(text='Hello ' + name.get() + ' ' + numberChosen.get()) #changing our label ttk.Label(monty, text="Enter a name:").grid(column=0, row =0, sticky='W') #ttk is not a python #adding a textbox entry widget name = tk.StringVar() nameEntered = ttk.Entry(monty, width=12, textvariable=name) nameEntered.grid(column=0, row=1, sticky=tk.W)
def create_gui(self): self.lbl_link = tk.Label(self, text="Link: ") self.txt_link = tk.Entry(self, width=50) self.btn_load_stream = tk.Button(self, text="Load stream", \ bg=TabDownload.btn_bg_color, fg=TabDownload.btn_fg_color) self.lbl_save = tk.Label(self, text="Save: ") self.txt_save = tk.Entry(self, width=50) self.btn_save_to = tk.Button(self, bg=TabDownload.btn_bg_color, \ fg=TabDownload.btn_fg_color, text="Browser...") self.btn_download = tk.Button(self, text="Dowload", \ bg=TabDownload.btn_bg_color, fg=TabDownload.btn_fg_color) self.btn_cancel = tk.Button(self, text="Cancel", \ bg=TabDownload.btn_bg_color, fg=TabDownload.btn_fg_color) self.lbl_progress = tk.Label(self, text="Progress:") self.pgsbar_progress = ttk.Progressbar( self, length=300, style='text.Horizontal.TProgressbar') self.lbl_progressInfo = tk.Label(self, text="Progress") self.pgsbar_progress['maximum'] = 100 self.style = ttk.Style(self) self.style.layout('text.Horizontal.TProgressbar', [('Horizontal.Progressbar.trough', { 'children': [('Horizontal.Progressbar.pbar', { 'side': 'left', 'sticky': 'ns' })], 'sticky': 'nswe' }), ('Horizontal.Progressbar.label', { 'sticky': '' })]) # , lightcolor=None, bordercolo=None, darkcolor=None self.style.configure('text.Horizontal.TProgressbar', text='0 %') self.lbl_list_stream = tk.Label(self, text="List streams:") self.lstbox_streams = tk.Listbox(self, width=80, height=10) self.create_scroll_bar() self.cv_thumbnail = tk.Canvas(self, width=TabDownload.thumbnail_w, \ height=TabDownload.thumbnail_h, bg='black') self.cv_thumbnail.create_text(TabDownload.thumbnail_w//2, TabDownload.thumbnail_h//2, fill="white", \ font="Arial 10 italic", \ text="Thumbnail review") self.lbl_vidtitle = tk.Label(self, text="Title:") self.lbl_vidduration = tk.Label(self, text="Duration:") self.lblframe_option = ttk.LabelFrame(self, text='Option') self.chk_var_convert_mp3 = tk.IntVar() self.ckb_convert_to_mp3 = tk.Checkbutton( self.lblframe_option, text="Convert to mp3", variable=self.chk_var_convert_mp3) self.lbl_audio_name = tk.Label(self.lblframe_option, text="File name:") self.txt_audio_name = tk.Entry(self.lblframe_option, width=15) self.btn_get_vidsub = tk.Button(self, text="Download video subtitle", \ bg=TabDownload.btn_bg_color, fg=TabDownload.btn_fg_color) self.lbl_rename_videofile = tk.Label(self.lblframe_option, text="Rename video file:") self.txt_rename_videofile = tk.Entry(self.lblframe_option, width=15) # Grid widgets self.lbl_link.grid(row=0, column=0, sticky='w', padx=5, pady=3) self.txt_link.grid(row=0, column=1, sticky='w', padx=5, pady=3) self.btn_load_stream.grid(row=0, column=2, sticky='w', padx=5, pady=3) self.lbl_save.grid(row=1, column=0, sticky='w', padx=5, pady=3) self.txt_save.grid(row=1, column=1, sticky='w', padx=5, pady=3) self.btn_save_to.grid(row=1, column=2, sticky='w', padx=5, pady=3) self.btn_download.grid(row=2, column=1, sticky='w', padx=5, pady=3) self.btn_cancel.grid(row=2, column=2, sticky='w', padx=5, pady=3) self.lbl_progress.grid(row=3, column=0, sticky='w', padx=5, pady=3) self.pgsbar_progress.grid(row=3, column=1, sticky='w', padx=5, pady=3) self.lbl_list_stream.grid(row=4, column=0, sticky='w', padx=2, pady=2) self.lstbox_streams.grid(row=5, column=0, rowspan=4, columnspan=3, sticky='w', padx=2, pady=2) self.cv_thumbnail.grid(row=0, column=4, rowspan=4, sticky='w', padx=10, pady=3) self.lbl_vidtitle.grid(row=4, column=4, sticky='w', padx=10, pady=2) self.lbl_vidduration.grid(row=5, column=4, sticky='nw', padx=10, pady=2) self.lblframe_option.grid(row=6, column=4, sticky='nw', padx=10, pady=2) self.btn_get_vidsub.grid(row=2, column=1, padx=5, pady=3) # Grid in option label frame self.lbl_rename_videofile.grid(row=0, column=0, sticky="w", padx=2, pady=2) self.txt_rename_videofile.grid(row=0, column=1, sticky="w", padx=2, pady=2) self.ckb_convert_to_mp3.grid(row=1, padx=2, pady=2, sticky="w") self.lbl_audio_name.grid(row=2, column=0, sticky="w", padx=2, pady=2) self.txt_audio_name.grid(row=2, column=1, sticky="e", padx=2, pady=2) # Init value self.txt_link.insert( tk.END, "https://www.youtube.com/watch?v=Z_yFB8wJSWA") # For debug self.txt_save.insert( tk.END, os.path.join(os.path.expanduser('~'), "Downloads\Video")) self.txt_audio_name.insert(tk.END, "Untitle.mp3")
# create three Radiobuttons using one variable radVar = tk.IntVar() # Next we are selecting a non-existing index value for radVar radVar.set(99) # Now we are creating all three Radiobutton widgets within one loop for col in range(3): curRad = tk.Radiobutton(win, text=colors[col], variable=radVar, value=col, command=radCall) curRad.grid(column=col, row=6, sticky=tk.W) # now row=6 # Create a container to hold labels buttons_frame = ttk.LabelFrame(win, text=' Labels in a Frame ') buttons_frame.grid(column=0, row=7) # Place labels into the container element ttk.Label(buttons_frame, text="Label1").grid(column=0, row=0, sticky=tk.W) ttk.Label(buttons_frame, text="Label2").grid(column=1, row=0, sticky=tk.W) ttk.Label(buttons_frame, text="Label3").grid(column=2, row=0, sticky=tk.W) name_entered.focus() # Place cursor into name Entry #====================== # Start GUI #====================== win.mainloop()
def _sb(msg): _status_msg.set(msg) def _alert(msg): messagebox.showinfo(message=msg) if __name__ == "__main__": _root = Tk() _root.title('Scrape app') _mainframe = ttk.Frame(_root, padding='5 5 5 5') _mainframe.grid(row=0, column=0, sticky=(E, W, N, S)) _url_frame = ttk.LabelFrame(_mainframe, text='URL', padding='5 5 5 5') _url_frame.grid(row=0, column=0, sticky=(E, W)) _url_frame.columnconfigure(0, weight=1) _url_frame.rowconfigure(0, weight=1) _url = StringVar() _url.set('http://localhost:8000') _url_entry = ttk.Entry(_url_frame, width=40, textvariable=_url) _url_entry.grid(row=0, column=0, sticky=(E, W, S, N), padx=5) _fetch_btn = ttk.Button(_url_frame, text='Fetch info', command=fetch_url) _fetch_btn.grid(row=0, column=1, sticky=W, padx=5) _img_frame = ttk.LabelFrame(_mainframe, text='Content', padding='9 0 0 0') _img_frame.grid(row=1, column=0, sticky=(N, S, E, W))
flower_boy += amount.get() else: flower_boy -= amount.get() vinyl_string = "blonde:{}\nnectar:{}\nflower boy:{}".format( blonde, nectar, flower_boy) vinyl_details.set(vinyl_string) amount.set("") ##########################################buy frame###################################################### #formatting variables.... background_color = "orange" #buy frame buy_frame = ttk.LabelFrame(root, width=360, height=180, text="Buy & Sell") buy_frame.grid(row=0, column=1) # Create a label for the account combobox vinyl_label = ttk.Label(buy_frame, text="Vinyl: ") vinyl_label.grid(row=1, column=1, padx=10, pady=3) # Set up a variable and option list for the account Combobox vinyl_names = ["blonde", "nectar", "flower boy"] chosen_vinyl = StringVar() chosen_vinyl.set(vinyl_names[0]) # Create a Combobox to select the account vinyl_box = ttk.Combobox(buy_frame, textvariable=chosen_vinyl, state="readonly")
def createWidgets(self): # Tab Control introduced here -------------------------------------- tabControl = ttk.Notebook(self.win) # Create Tab Control tab1 = ttk.Frame(tabControl) # Create a tab # tabControl.add(tab1, text='MySQL') # Add the tab -- COMMENTED OUT FOR CH08 tab2 = ttk.Frame(tabControl) # Add a second tab tabControl.add(tab2, text='Widgets') # Make second tab visible tabControl.pack(expand=1, fill="both") # Pack to make visible # ~ Tab Control introduced here ----------------------------------------- # We are creating a container frame to hold all other widgets self.mySQL = ttk.LabelFrame(tab1, text=' Python Database ') self.mySQL.grid(column=0, row=0, padx=8, pady=4) # Creating a Label ttk.Label(self.mySQL, text="Book Title:").grid(column=0, row=0, sticky='W') # Adding a Textbox Entry widget book = tk.StringVar() self.bookTitle = ttk.Entry(self.mySQL, width=34, textvariable=book) self.bookTitle.grid(column=0, row=1, sticky='W') # Adding a Textbox Entry widget book1 = tk.StringVar() self.bookTitle1 = ttk.Entry(self.mySQL, width=34, textvariable=book1) self.bookTitle1.grid(column=0, row=2, sticky='W') # Adding a Textbox Entry widget book2 = tk.StringVar() self.bookTitle2 = ttk.Entry(self.mySQL, width=34, textvariable=book2) self.bookTitle2.grid(column=0, row=3, sticky='W') # Creating a Label ttk.Label(self.mySQL, text="Page:").grid(column=1, row=0, sticky='W') # Adding a Textbox Entry widget page = tk.StringVar() self.pageNumber = ttk.Entry(self.mySQL, width=6, textvariable=page) self.pageNumber.grid(column=1, row=1, sticky='W') # Adding a Textbox Entry widget page = tk.StringVar() self.pageNumber1 = ttk.Entry(self.mySQL, width=6, textvariable=page) self.pageNumber1.grid(column=1, row=2, sticky='W') # Adding a Textbox Entry widget page = tk.StringVar() self.pageNumber2 = ttk.Entry(self.mySQL, width=6, textvariable=page) self.pageNumber2.grid(column=1, row=3, sticky='W') # Adding a Button self.action = ttk.Button(self.mySQL, text="Insert Quote", command=self.callBacks.insertQuote) self.action.grid(column=2, row=1) # Adding a Button self.action1 = ttk.Button(self.mySQL, text="Get Quotes", command=self.callBacks.getQuote) self.action1.grid(column=2, row=2) # Adding a Button self.action2 = ttk.Button(self.mySQL, text="Mody Quote", command=self.callBacks.modifyQuote) self.action2.grid(column=2, row=3) # Add some space around each widget for child in self.mySQL.winfo_children(): child.grid_configure(padx=2, pady=4) quoteFrame = ttk.LabelFrame(tab1, text=' Book Quotation ') quoteFrame.grid(column=0, row=1, padx=8, pady=4) # Using a scrolled Text control quoteW = 40 quoteH = 6 self.quote = scrolledtext.ScrolledText(quoteFrame, width=quoteW, height=quoteH, wrap=tk.WORD) self.quote.grid(column=0, row=8, sticky='WE', columnspan=3) # Add some space around each widget for child in quoteFrame.winfo_children(): child.grid_configure(padx=2, pady=4) #====================================================================================================== # Tab Control 2 #====================================================================================================== # We are creating a container frame to hold all other widgets -- Tab2 self.widgetFrame = ttk.LabelFrame(tab2, text=self.i18n.WIDGET_LABEL) self.widgetFrame.grid(column=0, row=0, padx=8, pady=4) # Creating three checkbuttons self.chVarDis = tk.IntVar() self.check1 = tk.Checkbutton(self.widgetFrame, text=self.i18n.disabled, variable=self.chVarDis, state='disabled') self.check1.select() self.check1.grid(column=0, row=0, sticky=tk.W) self.chVarUn = tk.IntVar() self.check2 = tk.Checkbutton(self.widgetFrame, text=self.i18n.unChecked, variable=self.chVarUn) self.check2.deselect() self.check2.grid(column=1, row=0, sticky=tk.W) self.chVarEn = tk.IntVar() self.check3 = tk.Checkbutton(self.widgetFrame, text=self.i18n.toggle, variable=self.chVarEn) self.check3.deselect() self.check3.grid(column=2, row=0, sticky=tk.W) # trace the state of the two checkbuttons self.chVarUn.trace( 'w', lambda unused0, unused1, unused2: self.checkCallback()) self.chVarEn.trace( 'w', lambda unused0, unused1, unused2: self.checkCallback()) # Radiobutton list colors = self.i18n.colors self.radVar = tk.IntVar() # Selecting a non-existing index value for radVar self.radVar.set(99) # Creating all three Radiobutton widgets within one loop for col in range(3): self.curRad = 'rad' + str(col) self.curRad = tk.Radiobutton(self.widgetFrame, text=colors[col], variable=self.radVar, value=col, command=self.callBacks.radCall) self.curRad.grid(column=col, row=6, sticky=tk.W, columnspan=3) # And now adding tooltips tt.createToolTip(self.curRad, 'This is a Radiobutton control.') # Create a container to hold labels labelsFrame = ttk.LabelFrame(self.widgetFrame, text=self.i18n.labelsFrame) labelsFrame.grid(column=0, row=7, pady=6) # Place labels into the container element - vertically ttk.Label(labelsFrame, text=self.i18n.chooseNumber).grid(column=0, row=0) self.lbl2 = tk.StringVar() self.lbl2.set(self.i18n.label2) ttk.Label(labelsFrame, textvariable=self.lbl2).grid(column=0, row=1) # Add some space around each label for child in labelsFrame.winfo_children(): child.grid_configure(padx=6, pady=1) number = tk.StringVar() self.combo = ttk.Combobox(self.widgetFrame, width=12, textvariable=number) self.combo['values'] = (1, 2, 4, 42, 100) self.combo.grid(column=1, row=7, sticky=tk.W) self.combo.current(0) self.combo.bind('<<ComboboxSelected>>', self.callBacks._combo) # Adding a Spinbox widget using a set of values self.spin = Spinbox(self.widgetFrame, values=(1, 2, 4, 42, 100), width=5, bd=8, command=self.callBacks._spin) self.spin.grid(column=2, row=7, sticky='W,', padx=6, pady=1) # Using a scrolled Text control scrolW = 40 scrolH = 1 self.scr = scrolledtext.ScrolledText(self.widgetFrame, width=scrolW, height=scrolH, wrap=tk.WORD) self.scr.grid(column=0, row=8, sticky='WE', columnspan=3) # Adding a TZ Button self.allTZs = ttk.Button(self.widgetFrame, text=self.i18n.timeZones, command=self.callBacks.allTimeZones) self.allTZs.grid(column=0, row=9, sticky='WE') # Adding local TZ Button self.localTZ = ttk.Button(self.widgetFrame, text=self.i18n.localZone, command=self.callBacks.localZone) self.localTZ.grid(column=1, row=9, sticky='WE') # Adding getTime TZ Button self.dt = ttk.Button(self.widgetFrame, text=self.i18n.getTime, command=self.callBacks.getDateTime) self.dt.grid(column=2, row=9, sticky='WE') # Create Manage Files Frame ------------------------------------------------ mngFilesFrame = ttk.LabelFrame(tab2, text=self.i18n.mgrFiles) mngFilesFrame.grid(column=0, row=1, sticky='WE', padx=10, pady=5) # Button Callback def getFileName(): print('hello from getFileName') fDir = path.dirname(__file__) fName = fd.askopenfilename(parent=self.win, initialdir=fDir) print(fName) self.fileEntry.config(state='enabled') self.fileEntry.delete(0, tk.END) self.fileEntry.insert(0, fName) if len(fName) > self.entryLen: self.fileEntry.config(width=len(fName) + 3) # Add Widgets to Manage Files Frame lb = ttk.Button(mngFilesFrame, text=self.i18n.browseTo, command=getFileName) lb.grid(column=0, row=0, sticky=tk.W) #----------------------------------------------------- file = tk.StringVar() self.entryLen = scrolW - 4 self.fileEntry = ttk.Entry(mngFilesFrame, width=self.entryLen, textvariable=file) self.fileEntry.grid(column=1, row=0, sticky=tk.W) #----------------------------------------------------- logDir = tk.StringVar() self.netwEntry = ttk.Entry(mngFilesFrame, width=self.entryLen, textvariable=logDir) self.netwEntry.grid(column=1, row=1, sticky=tk.W) def copyFile(): import shutil src = self.fileEntry.get() file = src.split('/')[-1] dst = self.netwEntry.get() + '\\' + file try: shutil.copy(src, dst) mBox.showinfo('Copy File to Network', 'Succes: File copied.') except FileNotFoundError as err: mBox.showerror('Copy File to Network', '*** Failed to copy file! ***\n\n' + str(err)) except Exception as ex: mBox.showerror('Copy File to Network', '*** Failed to copy file! ***\n\n' + str(ex)) cb = ttk.Button(mngFilesFrame, text=self.i18n.copyTo, command=copyFile) cb.grid(column=0, row=1, sticky=tk.E) # Add some space around each label for child in mngFilesFrame.winfo_children(): child.grid_configure(padx=6, pady=6) # Creating a Menu Bar ========================================================== menuBar = Menu(tab1) self.win.config(menu=menuBar) # Add menu items fileMenu = Menu(menuBar, tearoff=0) fileMenu.add_command(label=self.i18n.new) fileMenu.add_separator() fileMenu.add_command(label=self.i18n.exit, command=self.callBacks._quit) menuBar.add_cascade(label=self.i18n.file, menu=fileMenu) # Add another Menu to the Menu Bar and an item helpMenu = Menu(menuBar, tearoff=0) helpMenu.add_command(label=self.i18n.about) menuBar.add_cascade(label=self.i18n.help, menu=helpMenu) # Change the main windows icon self.win.iconbitmap(r'C:\Python34\DLLs\pyc.ico') # Using tkinter Variable Classes strData = tk.StringVar() strData.set('Hello StringVar') # It is not necessary to create a tk.StringVar() strData = tk.StringVar() strData = self.spin.get() # Place cursor into name Entry self.bookTitle.focus() # Add a Tooltip to the Spinbox tt.createToolTip(self.spin, 'This is a Spin control.') # Add Tooltips to more widgets tt.createToolTip(self.bookTitle, 'This is an Entry control.') tt.createToolTip(self.action, 'This is a Button control.') tt.createToolTip(self.scr, 'This is a ScrolledText control.')