我们从Python开源项目中,提取了以下25个代码示例,用于说明如何使用tkinter.ttk.LabelFrame()。
def createWidgets(self): tabControl = ttk.Notebook(self.win) tab1 = ttk.Frame(tabControl) tabControl.add(tab1, text='Tab 1') tabControl.pack(expand=1, fill="both") self.monty = ttk.LabelFrame(tab1, text=' Monty Python ') self.monty.grid(column=0, row=0, padx=8, pady=4) scr = scrolledtext.ScrolledText(self.monty, width=30, height=3, wrap=tk.WORD) scr.grid(column=0, row=3, sticky='WE', columnspan=3) menuBar = Menu(tab1) self.win.config(menu=menuBar) fileMenu = Menu(menuBar, tearoff=0) menuBar.add_cascade(label="File", menu=fileMenu) helpMenu = Menu(menuBar, tearoff=0) menuBar.add_cascade(label="Help", menu=helpMenu) self.createButtons()
def __init__(self, master): super().__init__(master, text="Levels", padding=4) self.lowest_level = Player.levelmeter_lowest self.pbvar_left = tk.IntVar() self.pbvar_right = tk.IntVar() pbstyle = ttk.Style() # pbstyle.theme_use("classic") # clam, alt, default, classic pbstyle.configure("green.Vertical.TProgressbar", troughcolor="gray", background="light green") pbstyle.configure("yellow.Vertical.TProgressbar", troughcolor="gray", background="yellow") pbstyle.configure("red.Vertical.TProgressbar", troughcolor="gray", background="orange") ttk.Label(self, text="dB").pack(side=tkinter.TOP) frame = ttk.LabelFrame(self, text="L.") frame.pack(side=tk.LEFT) self.pb_left = ttk.Progressbar(frame, orient=tk.VERTICAL, length=200, maximum=-self.lowest_level, variable=self.pbvar_left, mode='determinate', style='yellow.Vertical.TProgressbar') self.pb_left.pack() frame = ttk.LabelFrame(self, text="R.") frame.pack(side=tk.LEFT) self.pb_right = ttk.Progressbar(frame, orient=tk.VERTICAL, length=200, maximum=-self.lowest_level, variable=self.pbvar_right, mode='determinate', style='yellow.Vertical.TProgressbar') self.pb_right.pack()
def display_tab3(): monty3 = ttk.LabelFrame(display_area, text=' New Features ') monty3.grid(column=0, row=0, padx=8, pady=4) # Adding more Feature Buttons startRow = 4 for idx in range(24): if idx < 2: colIdx = idx col = colIdx else: col += 1 if not idx % 3: startRow += 1 col = 0 b = ttk.Button(monty3, text="Feature " + str(idx + 1)) b.grid(column=col, row=startRow) # Add some space around each label for child in monty3.winfo_children(): child.grid_configure(padx=8) #------------------------------------------
def __init__(self, parent, on_text="Active", off_text="Inactive", default_state=False, state="enabled", *args): ttk.LabelFrame.__init__(self, parent, labelanchor="n", *args) self.parent = parent self._on_text = on_text self._off_text = off_text self._default_state = default_state self._state = state self._fill = tk.Frame(self, height=5) self._variable = tk.IntVar() self._variable.set(default_state) self._button = ttk.Checkbutton(self, width=11, state=self._state, variable=self._variable, command=self._activate, style="TButton") self.configure(labelwidget=self._button) self.frame = ttk.Frame(self) self._activate()
def setup_tab2(tab): # new frame new_frame = ttk.LabelFrame(tab, text='New Project Name') new_frame.grid(columnspan=2, row=0, padx=5, pady=5, sticky='ew') # New Project name = tk.StringVar name_entered = ttk.Entry(new_frame, width=19, textvariable=name) name_entered.grid(column=0, row=0, padx=6, pady=5) name_entered.focus() # spacer spacer_label = ttk.Label(new_frame, text='') spacer_label.grid(columnspan=2, row=1, padx=5, pady=5) # add button and commands def add_command(): add_project(name_entered.get()) spacer_label.configure(text='Project was added!', foreground='green') name_entered.delete(0, "end") setup_tab1(TAB_1) TAB_1.update() add_button = ttk.Button(tab, text='Add New Project', command=add_command) add_button.grid(columnspan=2, row=3, pady=5)
def __init__(self, parent): self._window = tk.Toplevel(master=parent.frame) self._window.title("PMI Graph Settings") self._parent = parent self._data = parent.data self._color_settings = ttk.LabelFrame(master=self._window, text="Colors") self._color_settings.pack() self._colors = [] for index, relation in enumerate(self._data.relation_types): label = tk.Label(master=self._color_settings, text="{0} Color".format(relation)) btn = tk.Button(master=self._color_settings, text="Get Color", command=self._get_color_button(index)) label.grid(row=index, column=0, sticky="we") btn.grid(row=index, column=1) parent_color = self._parent._colors[index] self._colors.append([label, btn, parent_color]) # Use a better default here self._window.protocol("WM_DELETE_WINDOW", self.on_exit)
def __init__(self, parent): """ Create a new UI for the module Args: parent: A tk or ttk object """ super(ModuleUIFrame, self).__init__(parent) self.columnconfigure(0, weight=1) self.rowconfigure(1, weight=1) # Set default values from ....datatools import get_data data = get_data() # API Frame api_frame = ttk.LabelFrame(self, padding=8, text="Google API") api_frame.grid(row=0, column=0, sticky="W E N S") api_frame.columnconfigure(0, weight=1) # Add key fields self.google_api_key = tk.StringVar() ttk.Label(api_frame, text="Google API Key").grid(column=0, row=0, sticky="W E N S") ttk.Entry(api_frame, textvariable=self.google_api_key).grid( column=0, row=1, padx=0, pady=4, sticky="W E N S") self.soundcloud_client_id = tk.StringVar() ttk.Label(api_frame, text="SoundCloud Client ID").grid(column=0, row=2, sticky="W E N S") ttk.Entry(api_frame, textvariable=self.soundcloud_client_id).grid( column=0, row=3, padx=0, pady=4, sticky="W E N S") ttk.Button(api_frame, command=lambda: self.update_keys(), text="Update API Data").grid( column=0, row=4, padx=0, pady=4, sticky="W E N S") if "google_api_key" in data["discord"]["keys"]: self.google_api_key.set(data["discord"]["keys"]["google_api_key"]) if "soundcloud_client_id" in data["discord"]["keys"]: self.soundcloud_client_id.set(data["discord"]["keys"]["soundcloud_client_id"])
def __init__(self, parent, module_name, module_ui): """ Create a new base for a module UI Args: parent: A tk or ttk object module_name (str): The name of the module module_ui: The _ui.py file to add for the module """ super(ModuleUIBaseFrame, self).__init__(parent, padding=8) self.columnconfigure(0, weight=1) self.rowconfigure(1, weight=1) if module_ui is not None: # Module UI frame module_ui.ModuleUIFrame(self).grid(row=0, column=0, sticky="W E N S") else: logger.debug("No _ui.py found for '{}'".format(module_name)) # Help frame help_frame = ttk.LabelFrame(self, padding=8, text="Help") help_frame.grid(row=1, column=0, sticky="W E N S") help_frame.columnconfigure(0, weight=1) help_frame.rowconfigure(0, weight=1) # Find the help path _dir = os.path.realpath( os.path.join(os.getcwd(), os.path.dirname(__file__))) help_path = "{}/modules/{}/{}".format(_dir, module_name, "_help.json") if os.path.isfile(help_path): # Load the text helptools.add_help_text(help_frame, help_path) else: # Default message tk.Label(help_frame, text="No _help.json file found for '{}'".format(module_name)).grid(row=0, column=0, sticky="W E N S")
def display_tab2(): monty2 = ttk.LabelFrame(display_area, text=' Holy Grail ') monty2.grid(column=0, row=0, padx=8, pady=4) # Creating three checkbuttons chVarDis = tk.IntVar() check1 = tk.Checkbutton(monty2, text="Disabled", variable=chVarDis, state='disabled') check1.select() check1.grid(column=0, row=0, sticky=tk.W) chVarUn = tk.IntVar() check2 = tk.Checkbutton(monty2, text="UnChecked", variable=chVarUn) check2.deselect() check2.grid(column=1, row=0, sticky=tk.W ) chVarEn = tk.IntVar() check3 = tk.Checkbutton(monty2, text="Toggle", variable=chVarEn) check3.deselect() check3.grid(column=2, row=0, sticky=tk.W) # Create a container to hold labels labelsFrame = ttk.LabelFrame(monty2, text=' Labels in a Frame ') labelsFrame.grid(column=0, row=7) # Place labels into the container element - vertically ttk.Label(labelsFrame, text="Label1").grid(column=0, row=0) ttk.Label(labelsFrame, text="Label2").grid(column=0, row=1) # Add some space around each label for child in labelsFrame.winfo_children(): child.grid_configure(padx=8) #------------------------------------------
def create(self, **kwargs): return ttk.LabelFrame(self.root, **kwargs)
def toggle(self): """Switches the LabelFrame to the opposite state.""" self._variable.set(not self._variable.get()) self._activate() ##################################################
def __init__(self, parent, *args, **kwargs): BaseWindow.__init__(self, parent, *args, **kwargs) self.title("Information") self.frame_basic = ttk.LabelFrame(self.frame_widget, text="Basics") self.frame_basic.grid(row=0, column=0, padx=3, pady=3, sticky="nesw")
def insert_tk_labelframe(self, index: int or str="end", *args, **kwargs): """Insert a tk.LabelFrame into the game.""" widget = tk.LabelFrame(self.text, **kwargs) self.text.window_create(index, window=widget) return widget
def insert_ttk_labelframe(self, labelanchor: str="nw", text: str="", underline: int=None, padding: list=[], labelwidget: tk.Widget=None, width: int=None, height: int=None, index: int or str="end", *args, **kwargs): """Insert a ttk.LabelFrame into the game.""" widget = ttk.LabelFrame(self.text, labelanchor=labelanchor, text=text, underline=underline, padding=padding, labelwidget=labelwidget, width=width, height=height, **kwargs) self.text.window_create(index, window=widget) return widget
def setup_tab3(tab): # remove frame remove_frame = ttk.LabelFrame(tab, text='Remove Project') remove_frame.grid(columnspan=2, row=0, padx=5, pady=5, sticky='ew') # Remove Project project_to_axe = tk.StringVar() walking_dead = ttk.Combobox(remove_frame, width=18, textvariable=project_to_axe, state='readonly') walking_dead['values'] = PROJECT_NAMES walking_dead.grid(columnspan=2, row=0, padx=5, pady=5) walking_dead.current(INDEX) walking_dead.configure(state='enabled') if PROJECTS else walking_dead.configure(state='disabled') # spacer spacer_label = ttk.Label(remove_frame, text='') spacer_label.grid(columnspan=2, row=1, padx=5, pady=5) # add button and commands def remove_command(): choice = PROJECTS[PROJECT_NAMES.index(walking_dead.get())].id remove_project(choice, safe=False) spacer_label.configure(text='Project was removed!', foreground='green') walking_dead.set('') init_globals() setup_tab1(TAB_1) if not PROJECTS: walking_dead.configure(state='disabled') remove_button.configure(state='disabled') remove_button = ttk.Button(tab, text='Remove Project', command=remove_command) remove_button.grid(columnspan=2, row=3, pady=5) remove_button.configure(state='enabled') if PROJECTS else remove_button.configure(state='disabled')
def setup_tab4(tab): # about frame about_app = 'Python Time Tracker (pytt)\nVer: {}\n\n{}'.format(__version__, __author__) about_frame = ttk.LabelFrame(tab, text='About') about_frame.grid(columnspan=2, row=0, padx=5, pady=5, sticky='ew') about = ttk.Label(about_frame, text=about_app, justify='center') about.grid(columnspan=2, row=1, padx=5, pady=5) # about.grid(columnspan=2, rowspan=3, padx=5, pady=5)
def __init__(self, master, title, backend): super().__init__(master) self.geometry("+400+400") self.title(title) f = ttk.LabelFrame(self, text="Stats") ttk.Label(f, text="Connected to Database backend at: "+backend._pyroUri.location).pack() statstext = "Number of tracks in database: {0} -- Total playing time: {1}".format(backend.num_tracks, datetime.timedelta(seconds=backend.total_playtime)) ttk.Label(f, text=statstext).pack() f.pack() ttk.Label(self, text="Adding tracks etc. is done via the command-line interface for now.\n" "Type 'help' in the console there to see the commands available.").pack() ttk.Button(self, text="Ok", command=self.destroy).pack()
def __init__(self, parent): """ Create a new UI for the module Args: parent: A tk or ttk object """ super(ModuleUIFrame, self).__init__(parent) self.columnconfigure(0, weight=1) self.rowconfigure(0, weight=1) # API Frame api_frame = ttk.LabelFrame(self, padding=8, text="Google API") api_frame.grid(row=0, column=0, sticky="W E N S") api_frame.columnconfigure(0, weight=1) # Add key field self.reddit_api_user_agent = tk.StringVar() ttk.Label(api_frame, text="Reddit API User Agent").grid(column=0, row=0, sticky="W E N S") ttk.Entry(api_frame, textvariable=self.reddit_api_user_agent).grid( column=0, row=1, padx=0, pady=4, sticky="W E N S") self.reddit_api_client_id = tk.StringVar() ttk.Label(api_frame, text="Reddit API Client ID").grid(column=0, row=2, sticky="W E N S") ttk.Entry(api_frame, textvariable=self.reddit_api_client_id).grid( column=0, row=3, padx=0, pady=4, sticky="W E N S") self.reddit_api_client_secret = tk.StringVar() ttk.Label(api_frame, text="Reddit API Client Secret").grid(column=0, row=4, sticky="W E N S") ttk.Entry(api_frame, textvariable=self.reddit_api_client_secret).grid( column=0, row=5, padx=0, pady=4, sticky="W E N S") # Update keys button ttk.Button(api_frame, command=lambda: self.update_keys(), text="Update API Data").grid( column=0, row=6, padx=0, pady=4, sticky="W E N S") # Set default values from ....datatools import get_data data = get_data() if "reddit_api_user_agent" in data["discord"]["keys"]: self.reddit_api_user_agent.set(data["discord"]["keys"]["reddit_api_user_agent"]) if "reddit_api_client_id" in data["discord"]["keys"]: self.reddit_api_client_id.set(data["discord"]["keys"]["reddit_api_client_id"]) if "reddit_api_client_secret" in data["discord"]["keys"]: self.reddit_api_client_secret.set(data["discord"]["keys"]["reddit_api_client_secret"])
def createWidgets(): tabControl = ttk.Notebook(win) tab1 = ttk.Frame(tabControl) tabControl.add(tab1, text='Tab 1') tabControl.pack(expand=1, fill="both") monty = ttk.LabelFrame(tab1, text=' Mighty Python ') monty.grid(column=0, row=0, padx=8, pady=4) ttk.Label(monty, text="Enter a name:").grid(column=0, row=0, sticky='W') name = tk.StringVar() nameEntered = ttk.Entry(monty, width=12, textvariable=name) nameEntered.grid(column=0, row=1, sticky='W') action = ttk.Button(monty, text="Click Me!") action.grid(column=2, row=1) ttk.Label(monty, text="Choose a number:").grid(column=1, row=0) number = tk.StringVar() numberChosen = ttk.Combobox(monty, width=12, textvariable=number) numberChosen['values'] = (42) numberChosen.grid(column=1, row=1) numberChosen.current(0) scrolW = 30; scrolH = 3 scr = scrolledtext.ScrolledText(monty, width=scrolW, height=scrolH, wrap=tk.WORD) scr.grid(column=0, row=3, sticky='WE', columnspan=3) menuBar = Menu(tab1) win.config(menu=menuBar) fileMenu = Menu(menuBar, tearoff=0) menuBar.add_cascade(label="File", menu=fileMenu) helpMenu = Menu(menuBar, tearoff=0) menuBar.add_cascade(label="Help", menu=helpMenu) nameEntered.focus() #======================
def display_tab1(): # Container frame to hold all other widgets monty = ttk.LabelFrame(display_area, text=' Mighty Python ') monty.grid(column=0, row=0, padx=8, pady=4) # Adding a Label ttk.Label(monty, text="Enter a name:").grid(column=0, row=0, sticky='W') # Adding a Textbox Entry widget name = tk.StringVar() nameEntered = ttk.Entry(monty, width=12, textvariable=name) nameEntered.grid(column=0, row=1, sticky='W') ttk.Label(monty, text="Choose a number:").grid(column=1, row=0) number = tk.StringVar() numberChosen = ttk.Combobox(monty, width=12, textvariable=number) numberChosen['values'] = (1, 2, 4, 42, 100) numberChosen.grid(column=1, row=1) numberChosen.current(0) # Adding a Button action = ttk.Button(monty, text="Click Me!", command= lambda: clickMe(action, name, number)) action.grid(column=2, row=1) # Using a scrolled Text control scrolW = 30; scrolH = 3 scr = scrolledtext.ScrolledText(monty, width=scrolW, height=scrolH, wrap=tk.WORD) scr.grid(column=0, row=3, sticky='WE', columnspan=3) # Adding a Spinbox widget using a set of values spin = Spinbox(monty, values=(1, 2, 4, 42, 100), width=5, bd=8, command= lambda: _spin(spin, scr)) spin.grid(column=0, row=2, sticky='W') # Adding another Button clear = ttk.Button(monty, text="Clear Text", command= lambda: clearScrol(scr)) clear.grid(column=2, row=2) # Adding more Feature Buttons startRow = 4 for idx in range(12): if idx < 2: colIdx = idx col = colIdx else: col += 1 if not idx % 3: startRow += 1 col = 0 b = ttk.Button(monty, text="Feature " + str(idx+1)) b.grid(column=col, row=startRow) #------------------------------------------
def frame1(self): self.frame1 = ttk.LabelFrame(self.master, text = "Parameters", borderwidth = 2, relief = "groove") self.frame1.place(bordermode = "outside", relwidth = 0.99, relheight = 0.21, relx = 0, x = 5, y = 5, anchor = "nw") self.frame1.first_run = True # function function_label = ttk.Label(self.frame1, text = "Function") function_option_menu = ttk.OptionMenu(self.frame1, self.function, self.function.get(), *sorted(self.FUNCOPT)) # max_iter max_iter_label = ttk.Label(self.frame1, text = "Maximum number of iterations") max_iter_spinbox = Spinbox(self.frame1, from_ = 2, to_ = 9999, increment = 1, textvariable = self.max_iter, width = 6, justify = "right", takefocus = True) # fps fps_label = ttk.Label(self.frame1, text = "Delay between frames (ms)") fps_spinbox = Spinbox(self.frame1, from_ = 1, to_ = 1000, increment = 1, textvariable = self.interval, width = 6, justify = "right", takefocus = True) # seed seed_button = ttk.Checkbutton(self.frame1, text = "Fix seed", variable = self.fix_seed, takefocus = False) seed_spinbox = Spinbox(self.frame1, from_ = 0, to_ = self.MAX_SEED, increment = 1, textvariable = self.seed, width = 6, justify = "right", takefocus = True) # solver solver_label = ttk.Label(self.frame1, text = "Solver") solver_option_menu = ttk.OptionMenu(self.frame1, self.solver_name, self.solver_name.get(), *(self.EAOPT + self.MCOPT), command = self.select_widget) # constrain constrain_button = ttk.Checkbutton(self.frame1, text = "Constrain", variable = self.constrain, takefocus = False) # Layout function_label.place(relx = 0., x = 5, y = 5, anchor = "nw") function_option_menu.place(relx = 0., x = 75, y = 3, anchor = "nw") max_iter_label.place(relx = 0., x = 5, y = 30, anchor = "nw") max_iter_spinbox.place(width = 80, relx = 0., x = 220, y = 30, anchor = "nw") fps_label.place(relx = 0., x = 5, y = 55, anchor = "nw") fps_spinbox.place(width = 80, relx = 0., x = 220, y = 55, anchor = "nw") seed_button.place(relx = 0., x = 5, y = 80, anchor = "nw") seed_spinbox.place(width = 80, relx = 0., x = 220, y = 80, anchor = "nw") solver_label.place(relx = 0.35, x = 0, y = 5, anchor = "nw") solver_option_menu.place(relx = 0.35, x = 50, y = 3, anchor = "nw") constrain_button.place(relx = 0.35, x = 0, y = 80, anchor = "nw")
def __init__(self, parent): ttk.Frame.__init__(self, parent) self.parent = parent self['padding'] = '4' self.TKvariables = {} #Read in the defaults for key in defaults: if key[0:5] == 'graph' or key.find('ylims') >= 0: self.TKvariables.update({key:[]}) for val in range(len(defaults[key])): self.TKvariables[key].append(tk.StringVar(value=defaults[key][val])) else: self.TKvariables.update({key:tk.StringVar(value=defaults[key])}) num_vars = int(self.TKvariables['datalength'].get()) self.datalist = list(range(1,num_vars+1)) #Create a combobox containing the available COM ports comlst = self.get_comlst() self.COMbox = ttk.Labelframe(self, text='COM port to source data from') self.COMcombo = ttk.Combobox(self.COMbox, width=60, values=comlst, \ state='readonly', textvariable=self.TKvariables['COMport'],\ postcommand=self.updateCOMbox ) self.COMbox.grid(row = 0, column = 0, columnspan = 5) self.COMcombo.grid() #Create an "about" text box ABOUTframe = ttk.LabelFrame(self, text = 'What it does') ABOUTlabel = ttk.Label(ABOUTframe, text= \ 'Graphs data coming in over the serial port in a comma ' 'seperated variable string. Hover over each option to get ' 'a description of what the setting does', wraplength = 140) ABOUTframe.grid(row=1, column = 0, rowspan = 2, columnspan = 2, \ sticky = 'nw, se', padx= 3, pady = 5) CreateToolTip(ABOUTlabel,\ "The default values can be changed by opening defaults.py with a text " "editor and changing the values") ABOUTlabel.pack() #Create a Graph! and About buttons GObut = ttk.Button(self, text='Go!', command=self.goButton) GObut.grid(row=6, column = 0, sticky = 'we') ABOUTbut = ttk.Button(self, text='About', command=self.aboutButton) ABOUTbut.grid(row = 6, column = 1, sticky = 'we') #Create an instance of the class for the config panel notebook = ConfigNotebook(self, self) #Update the state of the graphs based on the defaults and grid notebook.updateGraphs() notebook.grid(row=1, column=3, columnspan=2, rowspan=6, sticky = 'nsew', \ padx = 5, pady = 5) #Bind the enter key to start the program self.parent.bind("<Return>", lambda event:self.goButton())