我们从Python开源项目中,提取了以下20个代码示例,用于说明如何使用ttk.Entry()。
def __init__(self, parent,r,c): ttk.Entry.__init__(self, parent) self.var = StringVar() self.config(textvariable = self.var) self.grid(row=r, column=c)
def __init__(self, master = None, **kwargs): ttk.Entry.__init__(self, master, "ttk::spinbox", **kwargs)
def _entry(self, variable, position, kwargs = {}): entry = ttk.Entry(self.frame1.sliders, textvariable = variable, justify = "right", takefocus = True, **kwargs) if position == 1: entry.place(width = 45, relx = 0.35, x = -3, y = 26, anchor = "nw") elif position == 2: entry.place(width = 45, relx = 0.35, x = -3, y = 71, anchor = "nw") elif position == 3: entry.place(width = 45, relx = 0.85, x = -3, y = 26, anchor = "nw") elif position == 4: entry.place(width = 45, relx = 0.85, x = -3, y = 71, anchor = "nw") return entry
def create(self, **kwargs): return ttk.Entry(self.root, **kwargs)
def _setup_widgets(self): btn = ttk.Button(self, text='Enter states and watch') entry = ttk.Entry(self, cursor='xterm', validate="key") entry['validatecommand'] = (self.register(self._new_state), '%W', '%P') entry.focus() self.update_widgets.append(btn) entry.validate() entry.pack(fill='x', padx=6) btn.pack(side='left', pady=6, padx=6, anchor='n') self.pack(fill='both', expand=1)
def show_window(self): self.mainframe.grid(column=0, row=0, sticky=(N, W, E, S)) self.mainframe.columnconfigure(0, weight=1) self.mainframe.rowconfigure(0, weight=1) ttk.Label(self.mainframe, text=" ").grid(column=0, row=0, sticky=(N,W)) ttk.Label(self.mainframe, text='1. Pair your Aurora').grid(column=1, row=1, sticky=(N, W)) ttk.Label(self.mainframe, text='IP Address').grid(column=1, row=2, sticky=(N, W)) ttk.Entry(self.mainframe, width=35, textvariable=self.ip_addr).grid(column=2, row=2, columnspan=2, sticky=(N, W)) ttk.Button(self.mainframe, width=12, text='Pair', command=self.authenticate_with_aurora).grid(column=4, row=2, sticky=(N,W)) ttk.Label(self.mainframe, text='2. Make a color palette').grid(column=1, row=3, sticky=(N, W)) ttk.Button(self.mainframe, text="Add Color", command=self.add_color_to_palette).grid(column=1, row=4, sticky=(N, W)) ttk.Label(self.mainframe, textvariable=self.curr_palette_string, wraplength=500).grid(column=2, row=4, columnspan=2, sticky=(N, W)) ttk.Button(self.mainframe, width=12, text="Clear palette", command=self.clear_palette).grid(column=4, row=4, sticky=(N, W)) if (not self.is_windows): ttk.Label(self.mainframe, text='3. Build your plugin').grid(column=1, row=5, sticky=(N, W)) else: ttk.Button(self.mainframe, width=18, text="Generate Palette", command=self.write_palette_for_sdk).grid(column=1, row=5, sticky=(N, W)) ttk.Label(self.mainframe, text='Plugin Location').grid(column=1, row=6, sticky=(N, W)) ttk.Entry(self.mainframe, width=35, textvariable=self.plugin_dir_path).grid(column=2, row=6, columnspan=2, sticky=(N, W)) ttk.Button(self.mainframe, width=12, text='Browse', command=self.get_plugin_dir).grid(column=4, row=6, sticky=(N, W)) if (not self.is_windows): ttk.Button(self.mainframe, text='Build', command=self.build_plugin).grid(column=2, row=7, columnspan=1, sticky=(N,E)) ttk.Button(self.mainframe, text='Upload & Run', command=self.play_plugin).grid(column=3, row=7, columnspan=1, sticky=N) ttk.Button(self.mainframe, width=12, text='Stop Plugin', command=self.stop_plugin).grid(column=4, row=7, columnspan=1, sticky=(N, W)) ttk.Label(self.mainframe, text=" ").grid(column=5, row=8, sticky=(N,W)) ttk.Label(self.mainframe, text=" ").grid(column=5, row=9, sticky=(N,W)) self.root.mainloop()
def get_passwd(self): self.passwd_window = Tkinter.Toplevel(self.frame2) self.passwd_window.title('Log In') x = self.frame2.winfo_rootx() y = self.frame2.winfo_rooty() self.passwd_window.geometry('350x130+%d+%d' % (x+150, y+100)) self.passwd_window.lift() self.passwd_window.columnconfigure(0, weight=1) self.passwd_window.columnconfigure(1, weight=1) self.passwd_window.columnconfigure(2, weight=1) self.passwd_window.columnconfigure(3, weight=2) self.passwd_window.columnconfigure(4, weight=2) self.passwd_window.columnconfigure(5, weight=1) self.passwd_window.rowconfigure(0, weight=1) self.passwd_window.rowconfigure(1, weight=2) self.passwd_window.rowconfigure(2, weight=2) self.passwd_window.rowconfigure(3, weight=2) self.passwd_window.rowconfigure(4, weight=1) self.passwd_window.resizable(False, False) reminder = ttk.Label(self.passwd_window, text='Please input the system password.') reminder.grid(row=1, column=1, columnspan=4, sticky='w') self.pswd = Tkinter.StringVar() pwentry = Tkinter.Entry(self.passwd_window, textvariable=self.pswd, width=30) pwentry.focus_set() pwentry.grid(row=2, column=3, columnspan=2, sticky='w', padx=10) pwentry.config(show='*') pswdlabel = ttk.Label(self.passwd_window, text='Password:') pswdlabel.grid(row=2, column=2, sticky='e', padx=10) confirm_but = ttk.Button(self.passwd_window, text='Confirm', command=self.pwconfirm) confirm_but.grid(row=3, column=4, sticky='w', padx=5) clear_but = ttk.Button(self.passwd_window, text='Clear', command=lambda: pwentry.delete(0, Tkinter.END)) clear_but.grid(row=3, column=3, sticky='e', padx=5) self.passwd_window.bind('<Return>', self.shortcut)
def get_passwd_ocf(self): self.passwd_window_ocf = Tkinter.Toplevel(self.frame3) self.passwd_window_ocf.title('Postgres Auth(System Password)') x = self.frame3.winfo_rootx() y = self.frame3.winfo_rooty() self.passwd_window_ocf.geometry('350x130+%d+%d' % (x+150, y+100)) self.passwd_window_ocf.lift() self.passwd_window_ocf.columnconfigure(0, weight=1) self.passwd_window_ocf.columnconfigure(1, weight=1) self.passwd_window_ocf.columnconfigure(2, weight=1) self.passwd_window_ocf.columnconfigure(3, weight=2) self.passwd_window_ocf.columnconfigure(4, weight=2) self.passwd_window_ocf.columnconfigure(5, weight=1) self.passwd_window_ocf.rowconfigure(0, weight=1) self.passwd_window_ocf.rowconfigure(1, weight=2) self.passwd_window_ocf.rowconfigure(2, weight=2) self.passwd_window_ocf.rowconfigure(3, weight=2) self.passwd_window_ocf.rowconfigure(4, weight=1) self.passwd_window_ocf.resizable(False, False) reminder = ttk.Label(self.passwd_window_ocf, text='Please input the system password.') reminder.grid(row=1, column=1, columnspan=4, sticky='w') self.pswd_ocf = Tkinter.StringVar() pwentry = Tkinter.Entry(self.passwd_window_ocf, textvariable=self.pswd_ocf, width=30) pwentry.focus_set() pwentry.grid(row=2, column=3, columnspan=2, sticky='w', padx=10) pwentry.config(show='*') pswdlabel = ttk.Label(self.passwd_window_ocf, text='Password:') pswdlabel.grid(row=2, column=2, sticky='e', padx=10) confirm_but = ttk.Button(self.passwd_window_ocf, text='Confirm', command=self.pwconfirm_ocf) confirm_but.grid(row=3, column=4, sticky='w', padx=5) clear_but = ttk.Button(self.passwd_window_ocf, text='Clear', command=lambda: pwentry.delete(0, Tkinter.END)) clear_but.grid(row=3, column=3, sticky='e', padx=5) self.passwd_window_ocf.bind('<Return>', self.shortcut3)
def start_cas(self): # add log in pop up here to let the user to input the username and password. Save then in cas_usr and cas_pw self.login_window = Tkinter.Toplevel(root) self.login_window.title('Cassandra Log in') self.login_window.lift() x = self.frame3.winfo_rootx() y = self.frame3.winfo_rooty() self.login_window.geometry('300x170+%d+%d' % (x+150, y+100)) self.login_window.rowconfigure(0, weight=1) self.login_window.rowconfigure(1, weight=1) self.login_window.rowconfigure(2, weight=1) self.login_window.rowconfigure(3, weight=1) self.login_window.rowconfigure(4, weight=1) self.login_window.columnconfigure(0, weight=1) self.login_window.columnconfigure(1, weight=1) self.login_window.columnconfigure(2, weight=1) self.login_window.columnconfigure(3, weight=1) self.login_window.resizable(False, False) unlabel = ttk.Label(self.login_window, text='Username:') unlabel.grid(row=1, column=1) pwlabel = ttk.Label(self.login_window, text='Password:') pwlabel.grid(row=2, column=1) self.username_cas = Tkinter.StringVar() self.password_cas = Tkinter.StringVar() unentry = ttk.Entry(self.login_window, textvariable=self.username_cas, width=20) unentry.focus_set() unentry.grid(row=1, column=2) pwentry = ttk.Entry(self.login_window, textvariable=self.password_cas, width=20) pwentry.grid(row=2, column=2) pwentry.configure(show='*') conf_but = ttk.Button(self.login_window, text='Confirm', command=self.checkuser) conf_but.grid(row=3, column=2, sticky='e') self.login_window.bind('<Return>', self.shortcut2)
def setUp(self): support.root_deiconify() self.entry = ttk.Entry()
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 createWidget(self): label1 = ttk.Label(self.win, text=u'??????:') label1.grid(sticky=tk.W, row=0, column=0) self.cityName = tk.StringVar() searchBox = ttk.Entry(self.win, width=12, textvariable=self.cityName) searchBox.grid(sticky=u'WE', row=0, column=1) searchBox.focus() searchBtn = ttk.Button(self.win, text=u'Search', command=self._searchBtn) searchBtn.grid(sticky=u'WE', row=1, columnspan=2) self.info = scrolledtext.ScrolledText(self.win, width=60, height=15, wrap=tk.WORD) self.info.grid(column=0, sticky=u'WE', columnspan=2)
def body(self, master, row, columns=DEFAULT_COLUMNS, **kwargs): """ Place the required elements using the grid layout method. Returns the number of rows taken by this element. """ label = ttk.Label(master, text=self.text) label.grid(row=row, column=0, columnspan=1, sticky="e") self.entry = ttk.Entry(master, textvariable=self.value) self.entry.grid(row=row, column=1, columnspan=columns - 1, sticky="ew") return 1
def body(self, master, row, columns=DEFAULT_COLUMNS, **kwargs): """ Place the required elements using the grid layout method. Returns the number of rows taken by this element. """ label = ttk.Label(master, text=self.text) label.grid(row=row, column=0, columnspan=1, sticky="e") self.entry = ttk.Entry(master, textvariable=self.value) self.entry.grid(row=row, column=1, columnspan=columns - 1, sticky="ew") if self.directory: self.choose = ttk.Button(master, text="Choose...", command=lambda: self.value.set( tkFileDialog.askdirectory())) else: self.choose = ttk.Button(master, text="Choose...", command=lambda: self.value.set( tkFileDialog.askopenfilename())) self.choose.grid(row=row + 1, column=1, sticky="w") if self.optional: self.clear = ttk.Button(master, text="Clear", command=lambda: self.value.set("")) self.clear.grid(row=row + 1, column=2, sticky="e") return 2
def body(self, master, row, columns=DEFAULT_COLUMNS, width=4, left=False, **kwargs): """ Add the labeled entry to the Frame *master* using grid at *row*. *width* controls the width of the Entry. *left* is ``True`` if the Entry is to the left of the Label. *columns* is the number of columns in *master*. Returns the number of rows taken by this element. """ if left: entry_column = 0 entry_sticky = "e" entry_width = 1 label_column = 1 label_sticky = "w" label_width = columns - 1 else: entry_column = 1 entry_sticky = "w" entry_width = columns - 1 label_column = 0 label_sticky = "e" label_width = 1 label = ttk.Label(master, text=self.text) label.grid(row=row, column=label_column, columnspan=label_width, sticky=label_sticky) self.entry = ttk.Entry(master, textvariable=self.value, width=width) self.entry.grid(row=row, column=entry_column, columnspan=entry_width, sticky=entry_sticky) return 1
def set_frame(self, root): scr_frame = ScrolledFrame(root) entries = {} stringvars = {} row_id = 0 set_btn = ttk.Button(scr_frame.frame, text='Set', command=self.set_params) set_btn.grid(row=row_id, column=3, sticky="ew") refresh_btn = ttk.Button(scr_frame.frame, text='Refresh', command=self.get_params) refresh_btn.grid(row=row_id, column=4, sticky="ew") recalc_btn = ttk.Button(scr_frame.frame, text='Recalc', command=self.recalc) recalc_btn.grid(row=row_id, column=5, sticky="ew") save_btn = ttk.Button(scr_frame.frame, text='SaveConfig', command=self.save_config) save_btn.grid(row=row_id, column=6, sticky="ew") row_id += 1 for idx, field in enumerate(self.shared_fields): lbl = ttk.Label(scr_frame.frame, text = field, anchor='w', width = 8) lbl.grid(row=row_id, column=idx+2, sticky="ew") if field in self.entry_fields: ent = ttk.Entry(scr_frame.frame, width=4) ent.grid(row=row_id+1, column=idx+2, sticky="ew") ent.insert(0, "0") entries[field] = ent elif field in self.status_fields: v= get_type_var(self.field_types[field]) lab = ttk.Label(scr_frame.frame, textvariable = v, anchor='w', width = 8) lab.grid(row=row_id+1, column=idx+2, sticky="ew") v.set('0') stringvars[field] = v row_id += 2 local_entry_fields = [ f for f in self.entry_fields if f not in self.shared_fields] local_status_fields = [ f for f in self.status_fields if f not in self.shared_fields] fields = ['assets'] + local_entry_fields + local_status_fields for idx, field in enumerate(fields): lbl = ttk.Label(scr_frame.frame, text = field, anchor='w', width = 8) lbl.grid(row=row_id, column=idx, sticky="ew") row_id += 1 for underlier in self.underliers: under_key = ','.join(underlier) inst_lbl = ttk.Label(scr_frame.frame, text=under_key, anchor="w", width = 8) inst_lbl.grid(row=row_id, column=0, sticky="ew") col_id = 1 entries[under_key] = {} for idx, field in enumerate(local_entry_fields): ent = ttk.Entry(scr_frame.frame, width=5) ent.grid(row=row_id, column=col_id+idx, sticky="ew") ent.insert(0, "0") entries[under_key][field] = ent col_id += len(local_entry_fields) stringvars[under_key] = {} for idx, field in enumerate(local_status_fields): v= get_type_var(self.field_types[field]) lab = ttk.Label(scr_frame.frame, textvariable = v, anchor='w', width = 8) lab.grid(row=row_id, column=col_id+idx, sticky="ew") v.set('0') stringvars[under_key][field] = v row_id +=1 self.entries = entries self.stringvars = stringvars self.get_params()
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()