Python tkinter.StringVar() Examples
The following are 30
code examples of tkinter.StringVar().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
tkinter
, or try the search function
.
Example #1
Source File: annotation_gui.py From SEM with MIT License | 9 votes |
def preferences(self, event=None): preferenceTop = tkinter.Toplevel() preferenceTop.focus_set() notebook = ttk.Notebook(preferenceTop) frame1 = ttk.Frame(notebook) notebook.add(frame1, text='general') frame2 = ttk.Frame(notebook) notebook.add(frame2, text='shortcuts') c = ttk.Checkbutton(frame1, text="Match whole word when broadcasting annotation", variable=self._whole_word) c.pack() shortcuts_vars = [] shortcuts_gui = [] cur_row = 0 j = -1 frame_list = [] frame_list.append(ttk.LabelFrame(frame2, text="common shortcuts")) frame_list[-1].pack(fill="both", expand="yes") for i, shortcut in enumerate(self.shortcuts): j += 1 key, cmd, bindings = shortcut name, command = cmd shortcuts_vars.append(tkinter.StringVar(frame_list[-1], value=key)) tkinter.Label(frame_list[-1], text=name).grid(row=cur_row, column=0, sticky=tkinter.W) entry = tkinter.Entry(frame_list[-1], textvariable=shortcuts_vars[j]) entry.grid(row=cur_row, column=1) cur_row += 1 notebook.pack() # # ? menu methods #
Example #2
Source File: application.py From Python-GUI-Programming-with-Tkinter with MIT License | 7 votes |
def load_settings(self): """Load settings into our self.settings dict.""" vartypes = { 'bool': tk.BooleanVar, 'str': tk.StringVar, 'int': tk.IntVar, 'float': tk.DoubleVar } # create our dict of settings variables from the model's settings. self.settings = {} for key, data in self.settings_model.variables.items(): vartype = vartypes.get(data['type'], tk.StringVar) self.settings[key] = vartype(value=data['value']) # put a trace on the variables so they get stored when changed. for var in self.settings.values(): var.trace('w', self.save_settings)
Example #3
Source File: Preferences.py From python-in-practice with GNU General Public License v3.0 | 6 votes |
def __init__(self, master, options): self.options = options board = self.options.board self.columns = tk.StringVar() self.columns.set(board.columns) self.rows = tk.StringVar() self.rows.set(board.rows) self.maxColors = tk.StringVar() self.maxColors.set(board.maxColors) self.delay = tk.StringVar() self.delay.set(board.delay) self.restore = tk.BooleanVar() self.restore.set(self.options.restore) self.showToolbar = tk.BooleanVar() self.showToolbar.set(self.options.showToolbar) super().__init__(master, "Preferences — {}".format(APPNAME), TkUtil.Dialog.OK_BUTTON|TkUtil.Dialog.CANCEL_BUTTON)
Example #4
Source File: toolkit.py From PickTrue with MIT License | 6 votes |
def __init__(self, master=None, store_name=None, **kwargs): super(FileBrowse, self).__init__(master=master, **kwargs) self.label_text = tk.StringVar() btn = tk.Button(self, text="下载到", command=self.choose_file) btn.pack( side=tk.LEFT, ) tk.Label(self, textvariable=self.label_text).pack( side=tk.LEFT, fill=tk.X, ) self.pack(fill=tk.X) self._store_name = store_name if store_name is not None: self._config = config_store save_path = self._config.op_read_path(store_name) or get_working_dir() else: self._config = None save_path = get_working_dir() self.label_text.set( save_path )
Example #5
Source File: application.py From Python-GUI-Programming-with-Tkinter with MIT License | 6 votes |
def load_settings(self): """Load settings into our self.settings dict.""" vartypes = { 'bool': tk.BooleanVar, 'str': tk.StringVar, 'int': tk.IntVar, 'float': tk.DoubleVar } # create our dict of settings variables from the model's settings. self.settings = {} for key, data in self.settings_model.variables.items(): vartype = vartypes.get(data['type'], tk.StringVar) self.settings[key] = vartype(value=data['value']) # put a trace on the variables so they get stored when changed. for var in self.settings.values(): var.trace('w', self.save_settings)
Example #6
Source File: ui_launch.py From Andromeda with MIT License | 6 votes |
def __init__(self, width=500, height=300): TkBase.__init__(self, width, height) self.plist_path = tk.StringVar() self.plist_path.set(os.path.abspath('.')) frame0 = tk.Frame(self.window) frame0.pack() frame1 = tk.Frame(self.window) frame1.pack() frame2 = tk.Frame(self.window) frame2.pack() self.__make_title_info(frame0, 0, 0) self.__make_title(frame1, 0, 1, 'Andromeda.plist 文件目录') self.__make_title_empty(frame1, 1, 0) self.__make_select_text(frame1, 1, 1, 1, self.plist_path) self.__make_title_empty(frame2, 0, 0) self.__make_select_confirm(frame2, 1, 0) self.window.mainloop()
Example #7
Source File: data_entry_app.py From Python-GUI-Programming-with-Tkinter with MIT License | 6 votes |
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.title("ABQ Data Entry Application") self.resizable(width=False, height=False) ttk.Label( self, text="ABQ Data Entry Application", font=("TkDefaultFont", 16) ).grid(row=0) self.recordform = DataRecordForm(self) self.recordform.grid(row=1, padx=10) self.savebutton = ttk.Button(self, text="Save", command=self.on_save) self.savebutton.grid(sticky=tk.E, row=2, padx=10) # status bar self.status = tk.StringVar() self.statusbar = ttk.Label(self, textvariable=self.status) self.statusbar.grid(sticky=(tk.W + tk.E), row=3, padx=10) self.records_saved = 0
Example #8
Source File: better_hello_tkinter.py From Python-GUI-Programming-with-Tkinter with MIT License | 6 votes |
def __init__(self, parent, *args, **kwargs): super().__init__(parent, *args, **kwargs) self.name = tk.StringVar() self.hello_string = tk.StringVar() self.hello_string.set("Hello World") name_label = ttk.Label(self, text="Name:") name_entry = ttk.Entry(self, textvariable=self.name) ch_button = ttk.Button(self, text="Change", command=self.on_change) hello_label = ttk.Label(self, textvariable=self.hello_string, font=("TkDefaultFont", 64), wraplength=600) # Layout form name_label.grid(row=0, column=0, sticky=tk.W) name_entry.grid(row=0, column=1, sticky=(tk.W + tk.E)) ch_button.grid(row=0, column=2, sticky=tk.E) hello_label.grid(row=1, column=0, columnspan=3) self.columnconfigure(1, weight=1)
Example #9
Source File: widgets.py From Python-GUI-Programming-with-Tkinter with MIT License | 6 votes |
def __init__(self, *args, error_var=None, **kwargs): self.error = error_var or tk.StringVar() super().__init__(*args, **kwargs) vcmd = self.register(self._validate) invcmd = self.register(self._invalid) style = ttk.Style() widget_class = self.winfo_class() validated_style = 'ValidatedInput.' + widget_class style.map( validated_style, foreground=[('invalid', 'white'), ('!invalid', 'black')], fieldbackground=[('invalid', 'darkred'), ('!invalid', 'white')] ) self.config( style=validated_style, validate='all', validatecommand=(vcmd, '%P', '%s', '%S', '%V', '%i', '%d'), invalidcommand=(invcmd, '%P', '%s', '%S', '%V', '%i', '%d') )
Example #10
Source File: application.py From Python-GUI-Programming-with-Tkinter with MIT License | 6 votes |
def load_settings(self): """Load settings into our self.settings dict.""" vartypes = { 'bool': tk.BooleanVar, 'str': tk.StringVar, 'int': tk.IntVar, 'float': tk.DoubleVar } # create our dict of settings variables from the model's settings. self.settings = {} for key, data in self.settings_model.variables.items(): vartype = vartypes.get(data['type'], tk.StringVar) self.settings[key] = vartype(value=data['value']) # put a trace on the variables so they get stored when changed. for var in self.settings.values(): var.trace('w', self.save_settings)
Example #11
Source File: widgets.py From Python-GUI-Programming-with-Tkinter with MIT License | 6 votes |
def __init__(self, *args, error_var=None, **kwargs): self.error = error_var or tk.StringVar() super().__init__(*args, **kwargs) vcmd = self.register(self._validate) invcmd = self.register(self._invalid) style = ttk.Style() widget_class = self.winfo_class() validated_style = 'ValidatedInput.' + widget_class style.map( validated_style, foreground=[('invalid', 'white'), ('!invalid', 'black')], fieldbackground=[('invalid', 'darkred'), ('!invalid', 'white')] ) self.config( style=validated_style, validate='all', validatecommand=(vcmd, '%P', '%s', '%S', '%V', '%i', '%d'), invalidcommand=(invcmd, '%P', '%s', '%S', '%V', '%i', '%d') )
Example #12
Source File: application.py From Python-GUI-Programming-with-Tkinter with MIT License | 6 votes |
def load_settings(self): """Load settings into our self.settings dict.""" vartypes = { 'bool': tk.BooleanVar, 'str': tk.StringVar, 'int': tk.IntVar, 'float': tk.DoubleVar } # create our dict of settings variables from the model's settings. self.settings = {} for key, data in self.settings_model.variables.items(): vartype = vartypes.get(data['type'], tk.StringVar) self.settings[key] = vartype(value=data['value']) # put a trace on the variables so they get stored when changed. for var in self.settings.values(): var.trace('w', self.save_settings)
Example #13
Source File: application.py From Python-GUI-Programming-with-Tkinter with MIT License | 6 votes |
def load_settings(self): """Load settings into our self.settings dict.""" vartypes = { 'bool': tk.BooleanVar, 'str': tk.StringVar, 'int': tk.IntVar, 'float': tk.DoubleVar } # create our dict of settings variables from the model's settings. self.settings = {} for key, data in self.settings_model.variables.items(): vartype = vartypes.get(data['type'], tk.StringVar) self.settings[key] = vartype(value=data['value']) # put a trace on the variables so they get stored when changed. for var in self.settings.values(): var.trace('w', self.save_settings)
Example #14
Source File: application.py From Python-GUI-Programming-with-Tkinter with MIT License | 6 votes |
def load_settings(self): """Load settings into our self.settings dict.""" vartypes = { 'bool': tk.BooleanVar, 'str': tk.StringVar, 'int': tk.IntVar, 'float': tk.DoubleVar } # create our dict of settings variables from the model's settings. self.settings = {} for key, data in self.settings_model.variables.items(): vartype = vartypes.get(data['type'], tk.StringVar) self.settings[key] = vartype(value=data['value']) # put a trace on the variables so they get stored when changed. for var in self.settings.values(): var.trace('w', self.save_settings)
Example #15
Source File: lineSettingsFrame.py From PyEveLiveDPS with GNU General Public License v3.0 | 6 votes |
def addLine(self, settingsList, dpsFrame): lineNumber = len(settingsList) settingsList.append({"transitionValue": "", "color": "#FFFFFF"}) settingsList[lineNumber]["transitionValue"] = tk.StringVar() settingsList[lineNumber]["transitionValue"].set(str(100*lineNumber)) removeButton = tk.Button(dpsFrame, text="X", command=lambda:self.removeLine(lineNumber, settingsList, dpsFrame)) font = tkFont.Font(font=removeButton['font']) font.config(weight='bold') removeButton['font'] = font removeButton.grid(row=lineNumber, column="0") lineLabel = tk.Label(dpsFrame, text="Threshold when the line changes color:") lineLabel.grid(row=lineNumber, column="1") initialThreshold = tk.Entry(dpsFrame, textvariable=settingsList[lineNumber]["transitionValue"], width=10) initialThreshold.grid(row=lineNumber, column="2") initialLabel = tk.Label(dpsFrame, text="Color:") initialLabel.grid(row=lineNumber, column="3") colorButton = tk.Button(dpsFrame, text=" ", command=lambda:self.colorWindow(settingsList[lineNumber], colorButton), bg=settingsList[lineNumber]["color"]) colorButton.grid(row=lineNumber, column="4")
Example #16
Source File: widgets.py From Python-GUI-Programming-with-Tkinter with MIT License | 6 votes |
def __init__(self, *args, error_var=None, **kwargs): self.error = error_var or tk.StringVar() super().__init__(*args, **kwargs) vcmd = self.register(self._validate) invcmd = self.register(self._invalid) style = ttk.Style() widget_class = self.winfo_class() validated_style = 'ValidatedInput.' + widget_class style.map( validated_style, foreground=[('invalid', 'white'), ('!invalid', 'black')], fieldbackground=[('invalid', 'darkred'), ('!invalid', 'white')] ) self.config( style=validated_style, validate='all', validatecommand=(vcmd, '%P', '%s', '%S', '%V', '%i', '%d'), invalidcommand=(invcmd, '%P', '%s', '%S', '%V', '%i', '%d') )
Example #17
Source File: widgets.py From Python-GUI-Programming-with-Tkinter with MIT License | 6 votes |
def __init__(self, *args, error_var=None, **kwargs): self.error = error_var or tk.StringVar() super().__init__(*args, **kwargs) vcmd = self.register(self._validate) invcmd = self.register(self._invalid) style = ttk.Style() widget_class = self.winfo_class() validated_style = 'ValidatedInput.' + widget_class style.map( validated_style, foreground=[('invalid', 'white'), ('!invalid', 'black')], fieldbackground=[('invalid', 'darkred'), ('!invalid', 'white')] ) self.config( style=validated_style, validate='all', validatecommand=(vcmd, '%P', '%s', '%S', '%V', '%i', '%d'), invalidcommand=(invcmd, '%P', '%s', '%S', '%V', '%i', '%d') )
Example #18
Source File: data_entry_app.py From Python-GUI-Programming-with-Tkinter with MIT License | 6 votes |
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.title("ABQ Data Entry Application") self.resizable(width=False, height=False) ttk.Label( self, text="ABQ Data Entry Application", font=("TkDefaultFont", 16) ).grid(row=0) self.recordform = DataRecordForm(self) self.recordform.grid(row=1, padx=10) self.savebutton = ttk.Button(self, text="Save", command=self.on_save) self.savebutton.grid(sticky="e", row=2, padx=10) # status bar self.status = tk.StringVar() self.statusbar = ttk.Label(self, textvariable=self.status) self.statusbar.grid(sticky="we", row=3, padx=10) self.records_saved = 0
Example #19
Source File: data_entry_app.py From Python-GUI-Programming-with-Tkinter with MIT License | 6 votes |
def __init__(self, parent, label='', input_class=ttk.Entry, input_var=None, input_args=None, label_args=None, **kwargs): super().__init__(parent, **kwargs) input_args = input_args or {} label_args = label_args or {} self.variable = input_var if input_class in (ttk.Checkbutton, ttk.Button, ttk.Radiobutton): input_args["text"] = label input_args["variable"] = input_var else: self.label = ttk.Label(self, text=label, **label_args) self.label.grid(row=0, column=0, sticky=(tk.W + tk.E)) input_args["textvariable"] = input_var self.input = input_class(self, **input_args) self.input.grid(row=1, column=0, sticky=(tk.W + tk.E)) self.columnconfigure(0, weight=1) self.error = getattr(self.input, 'error', tk.StringVar()) self.error_label = ttk.Label(self, textvariable=self.error) self.error_label.grid(row=2, column=0, sticky=(tk.W + tk.E))
Example #20
Source File: Main.py From python-in-practice with GNU General Public License v3.0 | 6 votes |
def create_variables(self): settings = TkUtil.Settings.Data self.restore = settings.get_bool(GENERAL, RESTORE, True) self.menuImages = {} self.toolbarImages = {} self.toolbars = [] self.toolbarMenu = None self.dockWindows = [] self.dockWindowMenu = None self.statusText = tk.StringVar() self.fontFamily = tk.StringVar() self.fontPointSize = tk.StringVar() self.bold = tk.BooleanVar() self.italic = tk.BooleanVar() self.alignment = tk.StringVar() self.recentFiles = [] self.findDialog = None self.x = self.y = self.dock = None
Example #21
Source File: application.py From Python-GUI-Programming-with-Tkinter with MIT License | 6 votes |
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.title("ABQ Data Entry Application") self.resizable(width=False, height=False) ttk.Label( self, text="ABQ Data Entry Application", font=("TkDefaultFont", 16) ).grid(row=0) self.recordform = v.DataRecordForm(self, m.CSVModel.fields) self.recordform.grid(row=1, padx=10) self.savebutton = ttk.Button(self, text="Save", command=self.on_save) self.savebutton.grid(sticky="e", row=2, padx=10) # status bar self.status = tk.StringVar() self.statusbar = ttk.Label(self, textvariable=self.status) self.statusbar.grid(sticky="we", row=3, padx=10) self.records_saved = 0
Example #22
Source File: workflowcreator.py From CEASIOMpy with Apache License 2.0 | 6 votes |
def __init__(self, master=None, **kwargs): tk.Frame.__init__(self, master, **kwargs) self.pack(fill=tk.BOTH) self.Options = WorkflowOptions() space_label = tk.Label(self, text=' ') space_label.grid(column=0, row=0) # Input CPACS file self.label = tk.Label(self, text=' Input CPACS file') self.label.grid(column=0, row=1) self.path_var = tk.StringVar() self.path_var.set(self.Options.cpacs_path) value_entry = tk.Entry(self, textvariable=self.path_var, width= 45) value_entry.grid(column=1, row=1) self.browse_button = tk.Button(self, text="Browse", command=self._browse_file) self.browse_button.grid(column=2, row=1, pady=5) # Notebook for tabs self.tabs = ttk.Notebook(self) self.tabs.grid(column=0, row=2, columnspan=3,padx=10,pady=10) self.TabPre = Tab(self, 'Pre') self.TabOptim = Tab(self, 'Optim') self.TabPost = Tab(self, 'Post') self.tabs.add(self.TabPre, text=self.TabPre.name) self.tabs.add(self.TabOptim, text=self.TabOptim.name) self.tabs.add(self.TabPost, text=self.TabPost.name) # General buttons self.close_button = tk.Button(self, text='Save & Quit', command=self._save_quit) self.close_button.grid(column=2, row=3)
Example #23
Source File: data_entry_app.py From Python-GUI-Programming-with-Tkinter with MIT License | 5 votes |
def __init__(self, *args, error_var=None, **kwargs): self.error = error_var or tk.StringVar() super().__init__(*args, **kwargs) vcmd = self.register(self._validate) invcmd = self.register(self._invalid) self.config( validate='all', validatecommand=(vcmd, '%P', '%s', '%S', '%V', '%i', '%d'), invalidcommand=(invcmd, '%P', '%s', '%S', '%V', '%i', '%d') )
Example #24
Source File: threading_queue_demo.py From Python-GUI-Programming-with-Tkinter with MIT License | 5 votes |
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.status = tk.StringVar(self, value='ready') tk.Label(self, textvariable=self.status).pack() tk.Button(self, text="Run process", command=self.go).pack() self.queue = Queue()
Example #25
Source File: application.py From Python-GUI-Programming-with-Tkinter with MIT License | 5 votes |
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.title("ABQ Data Entry Application") self.resizable(width=False, height=False) # new code for ch6 datestring = datetime.today().strftime("%Y-%m-%d") default_filename = "abq_data_record_{}.csv".format(datestring) self.filename = tk.StringVar(value=default_filename) self.settings_model = m.SettingsModel() self.load_settings() self.callbacks = { 'file->select': self.on_file_select, 'file->quit': self.quit } menu = v.MainMenu(self, self.settings, self.callbacks) self.config(menu=menu) self.recordform = v.DataRecordForm( self, m.CSVModel.fields, self.settings) # end new self.recordform.grid(row=1, padx=10) self.savebutton = ttk.Button(self, text="Save", command=self.on_save) self.savebutton.grid(sticky="e", row=2, padx=10) # status bar self.status = tk.StringVar() self.statusbar = ttk.Label(self, textvariable=self.status) self.statusbar.grid(sticky="we", row=3, padx=10) self.records_saved = 0
Example #26
Source File: widgets.py From Python-GUI-Programming-with-Tkinter with MIT License | 5 votes |
def __init__(self, parent, label='', input_class=None, input_var=None, input_args=None, label_args=None, field_spec=None, **kwargs): super().__init__(parent, **kwargs) input_args = input_args or {} label_args = label_args or {} if field_spec: field_type = field_spec.get('type', FT.string) input_class = input_class or self.field_types.get(field_type)[0] var_type = self.field_types.get(field_type)[1] self.variable = input_var if input_var else var_type() # min, max, increment if 'min' in field_spec and 'from_' not in input_args: input_args['from_'] = field_spec.get('min') if 'max' in field_spec and 'to' not in input_args: input_args['to'] = field_spec.get('max') if 'inc' in field_spec and 'increment' not in input_args: input_args['increment'] = field_spec.get('inc') # values if 'values' in field_spec and 'values' not in input_args: input_args['values'] = field_spec.get('values') else: self.variable = input_var if input_class in (ttk.Checkbutton, ttk.Button, ttk.Radiobutton): input_args["text"] = label input_args["variable"] = self.variable else: self.label = ttk.Label(self, text=label, **label_args) self.label.grid(row=0, column=0, sticky=(tk.W + tk.E)) input_args["textvariable"] = self.variable self.input = input_class(self, **input_args) self.input.grid(row=1, column=0, sticky=(tk.W + tk.E)) self.columnconfigure(0, weight=1) self.error = getattr(self.input, 'error', tk.StringVar()) self.error_label = ttk.Label(self, textvariable=self.error) self.error_label.grid(row=2, column=0, sticky=(tk.W + tk.E))
Example #27
Source File: widgets.py From Python-GUI-Programming-with-Tkinter with MIT License | 5 votes |
def __init__(self, *args, error_var=None, **kwargs): self.error = error_var or tk.StringVar() super().__init__(*args, **kwargs) vcmd = self.register(self._validate) invcmd = self.register(self._invalid) self.config( validate='all', validatecommand=(vcmd, '%P', '%s', '%S', '%V', '%i', '%d'), invalidcommand=(invcmd, '%P', '%s', '%S', '%V', '%i', '%d') )
Example #28
Source File: after_demo.py From Python-GUI-Programming-with-Tkinter with MIT License | 5 votes |
def __init__(self): super().__init__() self.status = tk.StringVar() tk.Label(self, textvariable=self.status).pack() tk.Button(self, text="Run Process", command=self.run_process).pack()
Example #29
Source File: toolkit.py From PickTrue with MIT License | 5 votes |
def __init__(self, master): tk.Frame.__init__(self, master) self.variable=tk.StringVar() self.label=tk.Label( self, bd=1, relief=tk.SUNKEN, anchor=tk.W, textvariable=self.variable, font=('arial', 16, 'normal') ) self.variable.set('') self.label.pack(fill=tk.X) self.pack(fill=tk.BOTH)
Example #30
Source File: test_widgets.py From Python-GUI-Programming-with-Tkinter with MIT License | 5 votes |
def test_init(self): # check error var setup self.assertIsInstance(self.vw1.error, tk.StringVar) # check validation config self.assertEqual(self.vw1.cget('validate'), 'all') self.assertEndsWith( self.vw1.cget('validatecommand'), '%P %s %S %V %i %d' ) self.assertEndsWith( self.vw1.cget('invalidcommand'), '%P %s %S %V %i %d' )