我们从Python开源项目中,提取了以下46个代码示例,用于说明如何使用ttk.Frame()。
def __init__(self, title=None): ttk.Frame.__init__(self, borderwidth=6) self.master.title(title) self.style = ttk.Style() # get default font size and family btn_font = self.style.lookup("TButton", "font") fsize = str(self.tk.eval("font configure %s -size" % btn_font)) self.font_family = self.tk.eval("font configure %s -family" % btn_font) if ' ' in self.font_family: self.font_family = '{%s}' % self.font_family self.fsize_prefix = fsize[0] if fsize[0] == '-' else '' self.base_fsize = int(fsize[1 if fsize[0] == '-' else 0:]) # a list to hold all the widgets that will have their states changed self.update_widgets = [] self._setup_widgets()
def __init__(self, parent, title="", optional = False, opt_func = None, *args, **options): Frame.__init__(self, parent, *args, **options) self.expanded = IntVar() self.expanded.set(0) self.enabled = IntVar() self.enabled.set(1) self.header = ttk.Frame(self) if optional: title_line = ttk.Checkbutton(self.header, text=title, variable=self.enabled, command=opt_func) else: title_line = ttk.Label(self.header, text=" %s" % (title)) title_line.pack(side="top", fill=X) self.toggle_button = ttk.Checkbutton(self.header, width=2, text='+', command=self.toggle_expanded, variable=self.expanded, style='Toolbutton') self.toggle_button.pack(side="left", fill=X) self.header.pack(fill=X, expand=1) self.sub_frame = Frame(self)
def __init__(self, parent, title="", *args, **options): Frame.__init__(self, parent, *args, **options) header = Frame(self, bg="white") Label(header, text=title, font=("Helvetica", 16)).pack(side='top', anchor='nw', pady=4) header.pack(side="top", anchor="nw", fill=X) self.info = Frame(self) self.info_label = StringVar() Label(self.info, textvar=self.info_label).pack(side="top") self.info.pack(side="right", anchor="nw", fill=BOTH) self.list = Frame(self) self.list.pack(side="left", anchor="nw", fill=BOTH) self.info_frames = {} self.active_item = None self.active_info = None
def add(self, item): item_label = Label(self.list, text=item["name"], justify="right", cursor="dotbox") item_label.bind("<Button-1>", self._click) item_label.pack(side="top", fill=X, anchor="nw", padx=(5,15)) info = Frame(self.info) Label(info, text="Executed commands:").pack(side="top", anchor="nw", padx=(0,20)) steps = Text(info, bg="grey", fg="blue", font=("Courier", 12), height=len(item["steps"])+1) steps.configure(state=NORMAL) for step in item["steps"]: steps.insert(END, " $ %s %s\n" % (step.split()[0].split("/")[-1], " ".join(step.split()[1:]))) steps.see(END) steps.configure(state=DISABLED) steps.pack(side="top", anchor="nw") result_frame = Frame(info) Label(result_frame, text="Results directory: ").pack(side="left", anchor="nw", padx=(0,20)) Label(result_frame, text=item["path"]).pack(side="left", anchor="nw", padx=(0,20)) Button(result_frame, text="Open", command=lambda p=item["path"]: open_in_file_browser(p) ).pack(side="left", anchor="nw", padx=(0,20)) result_frame.pack(side="top", anchor="nw") Button(info, text="Delete run", command=lambda p=item: self.remove(item_label, info, p) ).pack(side="top", anchor="nw", padx=(0,20)) self.info_frames[str(item_label)] = info
def __init__(self): self.root = Tk() self.root.title("Plugin Builder") self.mainframe = ttk.Frame(self.root) self.plugin_dir_path = StringVar() self.palette_path = StringVar() self.ip_addr = StringVar() self.curr_palette_string = StringVar() self.directory_divider = "/" self.palette = [] self.palette_entered = False self.is_windows = False self.saved_auth = "" self.curr_palette_string.set("") self.sound_module = soundModuleSimulatorWrapper.SoundModuleSimulatorWrapper(self) self.load_palette_from_file() self.get_auth() self.get_os_dir()
def create_custom_frame(self): self.custom_frame = ttk.Frame(self.mainframe) self.custom_title = ttk.Label(self.custom_frame, text='Custom tags:') self.artist_label = ttk.Label(self.custom_frame, text='Artist: ') self.artist_input = Text(self.custom_frame, width=20, height=1, font=self.font) self.title_label = ttk.Label(self.custom_frame, text='Title: ') self.title_input = Text(self.custom_frame, width=20, height=1, font=self.font) self.album_label = ttk.Label(self.custom_frame, text='Album: ') self.album_input = Text(self.custom_frame, width=20, height=1, font=self.font) self.cover_art = ttk.Button(self.custom_frame, text='Browse for cover art', command=self.cover_art_browse) self.cover_art_path = Entry(self.custom_frame, width=20, font=self.font) self.custom_submit = ttk.Button(self.custom_frame, text='Download using custom tags', command=self.custom) self.custom_title.grid(row=0, columnspan=2) self.artist_label.grid(column=0, row=1) self.artist_input.grid(column=1, row=1) self.title_label.grid(column=0, row=2) self.title_input.grid(column=1, row=2) self.album_label.grid(column=0, row=3) self.album_input.grid(column=1, row=3) self.cover_art.grid(column=0, row=4) self.cover_art_path.grid(column=1, row=4) self.custom_submit.grid(row=5, columnspan=2, sticky=EW, pady=10) self.custom_frame.pack(pady=10)
def __init__(self, parent): self.parent = parent tk.Frame.__init__(self, self.parent) self.vscroll = ttk.Scrollbar(self, orient=tk.VERTICAL) self.hscroll = ttk.Scrollbar(self, orient=tk.HORIZONTAL) self.console = tk.Text(self, wrap='none', width=60) self.console.config(yscrollcommand = self.vscroll.set) self.console.config(xscrollcommand = self.hscroll.set) self.vscroll.config(command = self.console.yview) self.hscroll.config(command = self.console.xview) self.console.grid(column=0,row=0, sticky=(tk.W, tk.N, tk.S, tk.E)) self.vscroll.grid(column=1, row=0, sticky=(tk.E,tk.N,tk.S)) self.hscroll.grid(column=0,row=1, sticky=(tk.E,tk.W,tk.S)) self.columnconfigure(0, weight=1) self.rowconfigure(0, weight=1) self.console.insert(tk.END, 'Started PIEFACE GUI\n*************************\n') self.console.config(state=tk.DISABLED)
def body(self, master): """ Add the UI elements to the edit window. Ordering and placement of UI elements in columns is defined by the ``element_layouts`` dictionary. """ main = ttk.Frame(master, padding=(3, 3, 12, 12)) main.grid(row=0, column=0, sticky="nsew") layout = element_layouts[type(self.element).__name__] for i, column_tuple in enumerate(layout): new_frame = ttk.Frame(master, padding=(3, 3, 12, 12)) new_frame.grid(row=0, column=i, sticky="nsew") row_no = 0 for row_frame_key in layout[i]: for ui_element in self.frame_dict[row_frame_key]: row_no += ui_element.body(new_frame, row_no, left=True) if 'fastq' in self.frame_dict: if self.element.counts_file is not None: self.toggle.rb_counts.invoke() else: self.toggle.rb_fastq.invoke()
def _layout_basic(self): """ Defines the basic layout of the application. """ main = ttk.Notebook(self.gui) main.pack(fill='both', expand='yes') # create a child frame for each application pane frames = (Frame(), Frame(), Frame(), Frame()) # add the pages to the handler main.add(frames[0], text='Experimental Design') main.add(frames[1], text='Simulate Datasets') main.add(frames[2], text='Run Pipelines') main.add(frames[3], text='Result Summary') # Add the log handler. log = ttk.Notebook(self.gui) log.pack(fill='both', expand='yes') log_frame = Frame() log.add(log_frame, text='Log') # ... and the logging console self.console = Text(log_frame, name="console", height=10) self.console.pack(side='bottom', anchor='sw', expand='yes', fill=BOTH) return frames
def _set_queue(self, queue): for child in self.queue.winfo_children(): child.destroy() if queue != ["('None', 'running')"]: for item in queue: item, status = eval(item) item = item.split('/')[-1] queue_item = Frame(self.queue) item_label = Label(queue_item, text="%s: %s" % (item, status)) item_label.pack(side="left", anchor="nw") queue_item.pack(side='top', anchor='nw', fill=X)
def _create_container(func): '''Creates a ttk Frame with a given master, and use this new frame to place the scrollbars and the widget.''' def wrapped(cls, master, **kw): container = ttk.Frame(master) return func(cls, container, **kw) return wrapped
def documentation(version, w, h): def _setdoc(evt): w = evt.widget index = int(w.curselection()[0]) doc = w.get(index) textfield.config(state=NORMAL) textfield.delete('1.0', END) textfield.insert('1.0', docdic[doc]) textfield.config(state=DISABLED) r = Toplevel() w = int(w/2) h = int(h/2) r.geometry('{}x{}+{}+{}'.format(w, h, int(w/2), int(h/2))) r.wm_title('Documentation accpy version {}'.format(version)) lf = Frame(r) lf.pack(side=LEFT, fill=BOTH, expand=False) rf = Frame(r) rf.pack(side=RIGHT, fill=BOTH, expand=True) docmenuopts = ['General', 'Lattice editor', 'Citation'] docmenu = Listbox(lf) for entry in docmenuopts: docmenu.insert(END, entry) docmenu.pack(fill=BOTH, expand=True) docmenu.bind('<<ListboxSelect>>', _setdoc) scrollbar = Scrollbar(orient="vertical") textfield = Text(rf, xscrollcommand=scrollbar.set) textfield.pack(fill=BOTH, expand=True)
def frame1_pop(self): if not self.frame1.first_run: self.frame1.pop.forget() self.frame1.pop = ttk.Frame(self.frame1, borderwidth = 0) self.frame1.pop.place(width = 170, height = 25, relx = 0.35, y = 30, anchor = "nw") if self.solver_name.get() in self.EAOPT: # popsize popsize_label = ttk.Label(self.frame1.pop, text = "Population size") popsize_spinbox = Spinbox(self.frame1.pop, from_ = 1, to_ = 999, increment = 1, textvariable = self.popsize, width = 3, justify = "right", takefocus = True) # Layout popsize_label.place(relx = 0, x = 0, y = 0, anchor = "nw") popsize_spinbox.place(width = 60, relx = 0, x = 110, y = 0, anchor = "nw")
def frame1_sync(self): if not self.frame1.first_run: self.frame1.sync.forget() self.frame1.sync = ttk.Frame(self.frame1, borderwidth = 0) self.frame1.sync.place(width = 170, height = 25, relx = 0.35, y = 55, anchor = "nw") if self.solver_name.get() in [ "CPSO", "PSO", "DE" ]: # sync sync_button = ttk.Checkbutton(self.frame1.sync, text = "Synchronize", variable = self.sync, takefocus = False) # Layout sync_button.place(relx = 0, x =0, y = 0, anchor = "nw")
def frame2(self): from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg self.frame2 = ttk.Frame(self.master, borderwidth = 2, relief = "groove") self.frame2.place(bordermode = "outside", relwidth = 0.99, relheight = 0.72, relx = 0, rely = 0.22, x = 5, y = 5, anchor = "nw") self.frame2.canvas = ttk.Frame(self.frame2, borderwidth = 0) self.frame2.canvas.place(relwidth = 1, relheight = 1, relx = 0, anchor = "nw") self.fig = Figure(figsize = (13, 6), facecolor = "white") self.canvas = FigureCanvasTkAgg(self.fig, master = self.frame2.canvas) self.fig.canvas.mpl_connect("button_press_event", self._onClick) self.canvas.get_tk_widget().pack()
def init_widget(self): if not self.frame1.first_run: self.frame1.sliders.forget() else: self.frame1.first_run = False self.frame1.sliders = ttk.Frame(self.frame1, borderwidth = 0) self.frame1.sliders.place(relwidth = 0.45, relheight = 1., relx = 0.55, anchor = "nw")
def __init__(self,root): self.mainframe = ttk.Frame(root) self.mainframe.grid(column=5, row=4, sticky=(N, W, E, S)) self.trace = [] #self.mainframe.rowconfigure(4, weight=1)
def create(self, **kwargs): return ttk.Frame(self.root, **kwargs)
def _setup_widgets(self): msg = ttk.Label(wraplength="4i", justify="left", anchor="n", padding=(10, 2, 10, 6), text=("Ttk is the new Tk themed widget set. One of the widgets it " "includes is a tree widget, which can be configured to " "display multiple columns of informational data without " "displaying the tree itself. This is a simple way to build " "a listbox that has multiple columns. Clicking on the " "heading for a column will sort the data by that column. " "You can also change the width of the columns by dragging " "the boundary between them.")) msg.pack(fill='x') container = ttk.Frame() container.pack(fill='both', expand=True) # XXX Sounds like a good support class would be one for constructing # a treeview with scrollbars. self.tree = ttk.Treeview(columns=tree_columns, show="headings") vsb = ttk.Scrollbar(orient="vertical", command=self.tree.yview) hsb = ttk.Scrollbar(orient="horizontal", command=self.tree.xview) self.tree.configure(yscrollcommand=vsb.set, xscrollcommand=hsb.set) self.tree.grid(column=0, row=0, sticky='nsew', in_=container) vsb.grid(column=1, row=0, sticky='ns', in_=container) hsb.grid(column=0, row=1, sticky='ew', in_=container) container.grid_columnconfigure(0, weight=1) container.grid_rowconfigure(0, weight=1)
def __init__(self): ttk.Frame.__init__(self) self.style = ttk.Style() self._setup_widgets()
def __init__(self, master=None, **kw): """ WIDGET-SPECIFIC OPTIONS locale, firstweekday, year, month, selectbackground, selectforeground """ # remove custom options from kw before initializating ttk.Frame fwday = kw.pop('firstweekday', calendar.MONDAY) year = kw.pop('year', self.datetime.now().year) month = kw.pop('month', self.datetime.now().month) locale = kw.pop('locale', None) sel_bg = kw.pop('selectbackground', '#ecffc4') sel_fg = kw.pop('selectforeground', '#05640e') self._date = self.datetime(year, month, 1) self._selection = None # no date selected ttk.Frame.__init__(self, master, **kw) self._cal = get_calendar(locale, fwday) self.__setup_styles() # creates custom styles self.__place_widgets() # pack/grid used widgets self.__config_calendar() # adjust calendar columns and setup tags # configure a canvas, and proper bindings, for selecting dates self.__setup_selection(sel_bg, sel_fg) # store items ids, used for insertion later self._items = [self._calendar.insert('', 'end', values='') for _ in range(6)] # insert dates in the currently empty calendar self._build_calendar() # set the minimal size for the widget self._calendar.bind('<Map>', self.__minsize)
def __setitem__(self, item, value): if item in ('year', 'month'): raise AttributeError("attribute '%s' is not writeable" % item) elif item == 'selectbackground': self._canvas['background'] = value elif item == 'selectforeground': self._canvas.itemconfigure(self._canvas.text, item=value) else: ttk.Frame.__setitem__(self, item, value)
def __getitem__(self, item): if item in ('year', 'month'): return getattr(self._date, item) elif item == 'selectbackground': return self._canvas['background'] elif item == 'selectforeground': return self._canvas.itemcget(self._canvas.text, 'fill') else: r = ttk.tclobjs_to_py({item: ttk.Frame.__getitem__(self, item)}) return r[item]
def add_results(self): try: self.results_images = self.q.get(0) self.search_progress.pack_forget() self.search_progress.destroy() self.cancel.pack_forget() self.cancel.destroy() if self.results_images == 0: self.reset() elif self.results_images == -1: # If the URL is invalid self.error = ttk.Label(self.mainframe, text='Error: Invalid URL', font=self.font, foreground='#ff0000') self.error.pack() # Create an error message self.enable_search() # Enable the search option again elif self.results_images == -2: self.error = ttk.Label(self.mainframe, text='Error: Network error', font=self.font, foreground='#ff0000') self.error.pack() # Create an error message self.enable_search() # Enable the search option again else: self.enable_search() self.results = self.results_images[0] self.images = self.results_images[1] self.results_frame = ttk.Frame(self.mainframe) self.results_label = ttk.Label(self.mainframe, text='Results:', font=self.font) self.results_label.pack() for i, result in enumerate(self.results): text = '%s\n%s\n%s' % (result[0], result[1], result[2]) self.result = ttk.Button(self.results_frame, text=text, image=self.images[i], compound=TOP, command=partial(self.download, i)) self.result.grid(column=i%4, row=i/4) self.results_frame.pack() self.create_custom_frame() except Queue.Empty: self.master.after(100, self.add_results)
def make_progress_frame_entry(self, label_text, video): # +-------------------------------------------------+ # | *Titel* start/pause] [cancel] | # | progress | # +-------------------------------------------------+ video['progress'] = tk.StringVar() video['progress'].set('Nog niet gestart') frame = ttk.Frame(self.progress_frame, relief=tk.GROOVE, borderwidth=10) video['frame'] = frame print(video['row']) frame.grid(row=video['row'], sticky=tk.W + tk.E + tk.N, column=0) # paned.grid(row=0, column=0, sticky=tk.E + tk.W + tk.N + tk.S) title = tk.Label(frame, text=label_text) title.grid(row=0, column=0, sticky=tk.W) video['start_pause'] = tk.StringVar() video['start_pause'].set('Start') btn = ttk.Button(frame, textvariable=video['start_pause'], style='Small.TButton', command=lambda: self.start_or_pause_video(video)) btn.grid(row=0, column=1, sticky=tk.E) cancel = ttk.Button(frame, text='Annuleren', style='Small.TButton', command=lambda: self.cancel_video(video)) cancel.grid(row=0, column=2, sticky=tk.E) progress = tk.Label(frame, textvariable=video['progress']) progress.grid(row=1, column=0, sticky=tk.W)
def __init__(self, parent): """ Initialise main window. """ self.parent = parent self.parent.title("PIEFACE Input GUI") # Make all errors propagated to MainWindow.parent call custom exception routine parent.report_callback_exception = self.report_callback_exception self.filenames = [] self.nbookmain = ttk.Notebook(self.parent) self.intab = ttk.Frame(self.nbookmain) self.logtab = ttk.Frame(self.nbookmain) self.nbookmain.add(self.intab, text='Input', sticky='nesw') self.nbookmain.add(self.logtab, text='Output log', sticky='nesw', state=tk.NORMAL) self.log = LogDisplay(self.logtab) #self.log.__init__(self.logtab) self.log.pack(expand=1, fill=tk.BOTH) self.init_menu() self.init_gui(self.intab) self.nbookmain.pack(expand=1, fill=tk.BOTH) self.intab.columnconfigure(0, weight=1) self.intab.rowconfigure(0, weight=1) self.nbookmain.select(self.logtab) self.nbookmain.select(self.intab) self.find_updates(verbose=False) self.phases = {}
def make_plot_win(self, selected): """ Create Toplevel window with selected data plotted """ if len(selected) == 0: tkMessageBox.showerror('Error','Please select files to plot results.') return for selection in selected: if self.filenames[selection] not in self.phases: tkMessageBox.showerror('Error','No results exist for {0}'.format(self.filebox.get(selection))) continue if len( self.phases[self.filenames[selection]].polyhedra ) == 0: tkMessageBox.showerror('Error','No valid polyhedra exist for {0}'.format(self.filebox.get(selection))) crystob = self.phases[self.filenames[selection]] self.plotwin = tk.Toplevel() self.plotwin.iconbitmap(iconloc) self.plotwin.title("PIEFACE Ellipsoid Plots") self.plotnb = ttk.Notebook(self.plotwin) tabs = {} figs = {} for poly in sorted(crystob.polyhedra): #Iterate through all polyhedra in Crystal object tabs[poly] = ttk.Frame(self.plotnb) self.plotnb.add(tabs[poly], text=poly, sticky='nesw') figs[poly] = PlotWindow(tabs[poly]) figs[poly].updateplot(getattr(crystob, poly+'_poly').ellipsoid, title=self.filebox.get(selection), pointcolor = getattr(crystob, poly+"_poly").pointcolours()) figs[poly].pack(expand=1, fill=tk.BOTH) self.plotnb.pack(expand=1, fill=tk.BOTH)
def __init__(self, parent): self.parent = parent tk.Frame.__init__(self, self.parent) self.updateplot(None) self.canvas.get_tk_widget().pack(side='top', fill='both', expand=1) self.toolbar = NavigationToolbar2TkAgg(self.canvas, self.parent) self.toolbar.update() self.canvas._tkcanvas.pack(fill='both', expand=1)
def __init__ (self, root): self.root = root root.title ("Course Page Downlaoder") mainframe = ttk.Frame(root, padding="3 3 12 12") mainframe.grid(column=0, row=0, sticky=(N, W, E, S)) mainframe.columnconfigure(0, weight=1) mainframe.rowconfigure(0, weight=1) self.mainframe = mainframe ttk.Label(mainframe, text="Registration Number").grid(row=0, column=0) self.regno = StringVar() self.pwd = StringVar() self.cache = IntVar() self.cache.set(1) self.progress = IntVar() self.progress.set(0) self.hint = StringVar() print "mama here" self.hint.set("Hit Download or Return to Proceed") self.regno_entry = ttk.Entry(self.mainframe, width=60, textvariable=self.regno) self.regno_entry.grid(column=0, row=1, sticky=(E)) self.pwd_label = ttk.Label(self.mainframe, text="Password").grid(row=2, column=0) self.pwd_entry = ttk.Entry(self.mainframe, width=60, show='*', textvariable=self.pwd) self.pwd_entry.grid(column=0, row=3, sticky=(E)) self.cb = ttk.Checkbutton(self.mainframe, text="Remember Me", variable = self.cache) self.cb.grid(column=0, row=4) self.dlbutton = ttk.Button(self.mainframe, text="Download", command= lambda: self.calculate()) self.dlbutton.grid(column = 0, row=5) for child in self.mainframe.winfo_children(): child.grid_configure(padx=5, pady=5) self.hint_label = ttk.Label(self.mainframe, text="Press Download to Begin", justify='center') self.hint_label.grid(row=6) self.prgbar = ttk.Progressbar(self.mainframe, orient='horizontal', mode='determinate', variable=self.progress).grid(column=0, row=7) self.regno_entry.focus()
def __init__(self, parent, root): ttk.Frame.__init__(self, parent) self.parent = parent self.root = root #Create the variables for the statusbar self.root.variables.update({'buffsize':tk.StringVar()}) self.root.variables.update({'lastline':tk.StringVar(value='Nothing Recieved')}) self.root.variables.update({'refreshrate':tk.StringVar(value=0)}) self.root.count = 0 #the number of lines we've recieved self.root.starttime = 0 #time when we started StatusBar(self, self.root).pack(fill='x', side='bottom') Graph(self, self.root).pack(fill='both', expand=True, side='top')
def __init__(self, parent, controller): ttk.Frame.__init__(self, parent) self.controller = controller self['padding'] = [0, 7, 0, 0] #Populate the serial configuration tab self.baudlist = (4800, 9600, 19200, 38400, 57600, 115200, 230400, 921600) self.databitslist = (7, 8) self.stopbitslist = (1, 2) self.paritylist = ('None', 'Even', 'Odd', 'Mark', 'Space') baudlabel = ttk.Label(self, text='Baudrate') baudbox = ttk.Combobox(self, width=8, values=self.baudlist, textvariable=self.controller.TKvariables['baud']) datalabel = ttk.Label(self, text='Data bits') databox = ttk.Combobox(self, width=8, values = self.databitslist, \ textvariable=self.controller.TKvariables['databits']) stopbitslabel = ttk.Label(self, text='Stop bits') stopbitsbox = ttk.Combobox(self, width=8, values=self.stopbitslist, \ textvariable=self.controller.TKvariables['stopbits']) paritylabel = ttk.Label(self, text='Parity') paritybox = ttk.Combobox(self, width=8, values=self.paritylist, \ textvariable=self.controller.TKvariables['parity']) #ttk.Label(self, text=' ').grid(row=1, column=0) baudlabel.grid(row=1, column = 1, padx=5) baudbox.grid(row=1, column=2, padx=5) datalabel.grid(row=2, column = 1, padx=5) databox.grid(row=2, column=2, padx=5) stopbitslabel.grid(row=3, column = 1, padx=5) stopbitsbox.grid(row=3, column=2, padx=5) paritylabel.grid(row=4, column = 1, padx=5) paritybox.grid(row=4, column=2, padx=5)
def body(self, master): frame = ttk.Frame(master, padding=(12, 6, 12, 6)) frame.pack() dialog_text_label = ttk.Label(frame, textvariable=self.dialog_text) dialog_text_label.grid(column=0, row=0, sticky="nsew")
def body(self, master): frame = ttk.Frame(master, padding=(12, 6, 12, 6)) frame.pack() dialog_text_label = ttk.Label(frame, textvariable=self.dialog_text) dialog_text_label.grid(column=0, row=0, sticky="nsew") self.run_button = tk.Button(frame, text="Begin", width=10, command=self.runner, default="active") self.run_button.grid(column=0, row=1, sticky="nsew")
def body(self, master): row_no = self.name_tk.body(master, 0) row_no += self.output_directory_tk.body(master, row_no) element_types = ttk.Frame(master, padding=(3, 3, 12, 12)) element_types.grid(column=0, row=row_no, sticky="nsew", columnspan=DEFAULT_COLUMNS) message = ttk.Label(element_types, text="Root object type:") message.grid(column=0, row=0) label = ttk.Label(element_types, text="Experiment") label.grid(column=0, row=1, sticky="w") rb = ttk.Radiobutton(element_types, text="Experiment", variable=self.element_tkstring, value="Experiment") rb.grid(column=0, row=2, sticky="w") rb.invoke() label = ttk.Label(element_types, text="Selection") label.grid(column=0, row=3, sticky="w") rb = ttk.Radiobutton(element_types, text="Selection", variable=self.element_tkstring, value="Selection") rb.grid(column=0, row=4, sticky="w") label = ttk.Label(element_types, text="SeqLib") label.grid(column=0, row=5, sticky="w") for i, k in enumerate(seqlib_label_text.keys()): rb = ttk.Radiobutton(element_types, text=seqlib_label_text[k], variable=self.element_tkstring, value=k) rb.grid(column=0, row=(i + 6), sticky="w")
def buttonbox(self): """ Display only one button. """ box = tk.Frame(self) w = tk.Button(box, text="OK", width=10, command=self.ok, default="active") w.pack(side="left", padx=5, pady=5) self.bind("<Return>", self.ok) box.pack()
def __init__(self, root, ac): ttk.Frame.__init__(self, root) self.root = root self.params = {} self.params_last_content = {} self.alt_files = {} self.bookmarks_file = ac.config["bookmark_filename"] self.log_file = ac.config["log_filename"] self.build(ac) self.params["cbb_mode1"].current(0) self.focus_force() self.update() # bookmarks loading on start self.bookmarks = Bookmarks(self.tree) self.bookmarks.load(self.bookmarks_file, ",") self.scan_thread = None self.sync_thread = None self.scan_mode = None self.scanning = None self.selected_bookmark = None self.scanq = STMessenger() self.syncq = STMessenger() self.new_bookmark_list = [] self.bind_all("<1>", lambda event:self.focus_set(event)) self.ac = ac self.buildmenu(root)
def __init__(self): ttk.Frame.__init__(self, borderwidth=3) self.style = ttk.Style() # XXX Ideally I wouldn't want to create a Tkinter.IntVar to make # it works with Checkbutton variable option. self.theme_autochange = Tkinter.IntVar(self, 0) self._setup_widgets()
def __init__(self): self.root = Tk() self.root.title("Dependencies") self.menubar = Menu(self.root) self.filemenu = Menu(self.menubar, tearoff=0) self.filemenu.add_command(label="Open", command=self.setRootFolder) self.filemenu.add_separator() self.filemenu.add_command(label="Exit", command=self.root.quit) self.menubar.add_cascade(label="File", menu=self.filemenu) self.root.config(menu=self.menubar) self.mainframe = ttk.Frame(self.root, width=300, height=300) self.root.columnconfigure(0, weight=1) self.root.rowconfigure(0, weight=1) self.mainframe.grid(column=0, row=0, sticky = "NSEW") self.hrulercanvas = Canvas(self.mainframe, width=300, borderwidth=0, background="#ffffff") self.vrulercanvas = Canvas(self.mainframe, height=300, borderwidth=0, background="#ffffff") self.deps_canvas = Canvas(self.mainframe, width=300, height=300, borderwidth=0, background="#ffffff") self.vscrollbar = ttk.Scrollbar(self.mainframe, orient=VERTICAL) self.hscrollbar = ttk.Scrollbar(self.mainframe, orient=HORIZONTAL) self.vscrollbar.config(command=self.yview) self.hscrollbar.config(command=self.xview) self.deps_canvas.config(yscrollcommand=self.vscrollbar.set) self.deps_canvas.config(xscrollcommand=self.hscrollbar.set) self.hrulercanvas.grid(row=0, column=1, sticky="EW") self.vrulercanvas.grid(row=1, column=0, sticky="NS") self.deps_canvas.grid(row=1, column=1, sticky="NSEW") self.vscrollbar.grid(row=1, column=2, sticky="NS") self.hscrollbar.grid(row=2, column=1, sticky="EW") self.hrulerframe = ttk.Frame(self.hrulercanvas) self.vrulerframe = ttk.Frame(self.vrulercanvas) self.hrulerframe.bind("<Configure>", self._onHRulerCanvasConfigure) self.vrulerframe.bind("<Configure>", self._onVRulerCanvasConfigure) self.hrulerwindow = self.hrulercanvas.create_window(0, 0, window=self.hrulerframe, anchor="nw", tags="self.hrulerframe") self.vrulerwindow = self.vrulercanvas.create_window(0, 0, window=self.vrulerframe, anchor="nw", tags="self.vrulerframe") self.deps_frame = ttk.Frame(self.deps_canvas) self.deps_frame.bind("<Configure>", self._onDepsCanvasConfigure) self.deps_window = self.deps_canvas.create_window(0, 0, window=self.deps_frame, anchor="nw", tags="self.deps_frame") self.mainframe.columnconfigure(0, weight=0) self.mainframe.columnconfigure(1, weight=1) self.mainframe.columnconfigure(2, weight=0) self.mainframe.rowconfigure(0, weight=0) self.mainframe.rowconfigure(1, weight=1) self.mainframe.rowconfigure(2, weight=0)
def __init__(self, master): self.master = master self.font = ('Segoe UI', 10) self.master.minsize(width=1280, height=720) self.master.maxsize(width=1280, height=720) self.canvas = Canvas(self.master, bd=0, highlightthickness=0) self.mainframe = ttk.Frame(self.canvas) self.scrollbar = Scrollbar(self.master, orient='vertical', command=self.canvas.yview) self.canvas.configure(yscrollcommand=self.scrollbar.set) self.scrollbar.pack(side=RIGHT, fill=Y) self.canvas.pack(side=TOP, fill=BOTH, expand=1) self.canvas.create_window((640, 0), window=self.mainframe, anchor=N, tags='self.mainframe') self.mainframe.bind('<Configure>', self.configure) self.footer = Frame(self.master, bg='#ddd') self.credits = Label(self.footer, text='AudioJack v0.4.0', font=('Segoe UI', 14), bg='#ddd') # Use Tkinter label because ttk does not make it easy to change colors. self.support_link = Label(self.footer, text='Support', font=('Segoe UI', 14), fg='#167ac6', bg='#ddd') self.support_link.bind('<Enter>', self.enter_link) self.support_link.bind('<Button-1>', self.open_url) self.support_link.bind('<Leave>', self.leave_link) self.credits.pack(side=LEFT) self.support_link.pack(side=RIGHT) self.footer.pack(side=BOTTOM, fill=X) self.canvas.bind_all('<MouseWheel>', self.scroll) self.title = ttk.Label(self.mainframe, text='AudioJack', font=('Segoe UI', 24)) self.title.pack() self.url = ttk.Label(self.mainframe, text='Enter a YouTube or SoundCloud URL below.', font=self.font) self.url.pack() self.url_input = Text(self.mainframe, width=40, height=1, font=self.font, wrap=NONE) self.url_input.bind('<Return>', self.search) self.url_input.bind('<Control-Key-a>', self.select_all) self.url_input.bind('<Control-Key-A>', self.select_all) self.url_input.pack() self.submit = ttk.Button(self.mainframe, text='Go!', command=self.search) self.submit.pack()
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())
def AObutton(self, graphnum): toplvl = tk.Toplevel() toplvl.withdraw() frame = ttk.Frame(toplvl, padding=[2, 3, 3, 0]) boxwidth = 15 #Create the labels lbl = ttk.Label(frame, text='Label') CreateToolTip(lbl, \ 'This text will show up in the legend and the log file') lbl.grid(row=0, column=1) mult = ttk.Label(frame, text='Multiplier') CreateToolTip(mult, \ 'Multiply by this value') mult.grid(row=0, column=2) offset = ttk.Label(frame, text='Offset') CreateToolTip(offset, \ 'Add this value. Happens AFTER the data is multiplied') offset.grid(row=0, column=3) dashed = ttk.Label(frame, text='Dashed') CreateToolTip(dashed, \ 'If checked, the line will be dashed') dashed.grid(row=0, column=4) ttk.Label(frame, text='Line 1').grid(row=1, column=0, padx=2) ttk.Label(frame, text='Line 2').grid(row=2, column=0, padx=2) ttk.Label(frame, text='Line 3').grid(row=3, column=0, padx=2) for row in range(1,3+1): key = 'graph'+str(graphnum)+'line'+str(row) #Label ttk.Entry(frame, width=boxwidth, \ textvariable=self.controller.TKvariables[key][0]).grid(row=row, column=1) #Multiplier ttk.Entry(frame, width=boxwidth, \ textvariable=self.controller.TKvariables[key][4]).grid(row=row, column=2) #Offset ttk.Entry(frame, width=boxwidth, \ textvariable=self.controller.TKvariables[key][5]).grid(row=row, column=3) #Dashed ttk.Checkbutton(frame, onvalue='--', offvalue='-', \ variable=self.controller.TKvariables[key][3]).grid(row=row, column=4) ttk.Button(frame, text='OK', command=toplvl.destroy).grid(row=5,\ column=3, columnspan=2, sticky='ew', pady=4) #Center the window frame.grid() toplvl.update() scrwidth = toplvl.winfo_screenwidth() scrheight = toplvl.winfo_screenheight() winwidth = toplvl.winfo_reqwidth() winheight = toplvl.winfo_reqheight() winposx = int(round(scrwidth/2 - winwidth/2)) winposy = int(round(scrheight/2 - winheight/2)) toplvl.geometry('{}x{}+{}+{}'.format(winwidth, winheight, winposx, winposy)) toplvl.deiconify()
def __init__(self, parent, root): ttk.Frame.__init__(self, parent) self.parent = parent self.root = root self['borderwidth'] = 2 self['relief'] = 'sunken' COMlabel = ttk.Label(self, text= \ self.root.variables['COMport'][0:5].strip() + ':') baudLabel = ttk.Label(self, text= \ str(self.root.variables['baud'].strip())) COMlabel.pack(side='left', padx=0) baudLabel.pack(side='left', padx=0) ttk.Separator(self, orient='vertical').pack(side='left', fill='y', padx=5) buffLabel = ttk.Label(self, text='Serial Buffer:') buffLabel.pack(side='left', padx=0) buffBar = ttk.Progressbar(self, orient='horizontal', length=50,\ mode='determinate', variable=self.root.variables['buffsize'],\ maximum=io.DEFAULT_BUFFER_SIZE) buffBar.pack(side='left') ttk.Separator(self, orient='vertical').pack(side='left', fill='y', padx=5) lastLabel = ttk.Label(self, text='Last line Recieved: ') lastLabel.pack(side='left') lastLine = ttk.Label(self, textvariable=self.root.variables['lastline'], \ font=('Courier', 8)) lastLine.pack(side='left') ttk.Separator(self, orient='vertical').pack(side='left', fill='y', padx=5) updateLabel = ttk.Label(self, text='Data Recieved at: ') updateLabel.pack(side='left') updateRate = ttk.Label(self, textvariable=self.root.variables['refreshrate']) updateRate.pack(side='left') ttk.Label(self, text='Hz (Est)').pack(side='left') ttk.Separator(self, orient='vertical').pack(side='left', fill='y', padx=5) if self.root.variables['log2file'] == 'on': self.root.toggleLogButton = ttk.Button(self, text='Turn Logging Off', command = self.toggleLog) self.root.toggleLogButton.pack(side='left')