本文整理汇总了Python中tkinter.StringVar方法的典型用法代码示例。如果您正苦于以下问题:Python tkinter.StringVar方法的具体用法?Python tkinter.StringVar怎么用?Python tkinter.StringVar使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tkinter
的用法示例。
在下文中一共展示了tkinter.StringVar方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: import tkinter [as 别名]
# 或者: from tkinter import StringVar [as 别名]
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
)
示例2: __init__
# 需要导入模块: import tkinter [as 别名]
# 或者: from tkinter import StringVar [as 别名]
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)
示例3: __init__
# 需要导入模块: import tkinter [as 别名]
# 或者: from tkinter import StringVar [as 别名]
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()
示例4: __init__
# 需要导入模块: import tkinter [as 别名]
# 或者: from tkinter import StringVar [as 别名]
def __init__(self, root, resource_dir, lang="fr"):
ttk.Frame.__init__(self, root)
self.resource_dir = resource_dir
self._lang = None
langs = os.listdir(os.path.join(self.resource_dir, "master"))
if langs:
self._lang = (lang if lang in langs else langs[0])
self.items = (os.listdir(os.path.join(self.resource_dir, "master", self._lang)) if self._lang else [])
self.items.sort(key=lambda x: x.lower())
max_length = max([len(item) for item in self.items])
self.select_workflow_label = ttk.Label(root, text=u"select workflow:")
#strVar = tkinter.StringVar()
self.masters = tkinter.Listbox(root, width=max_length+1, height=len(self.items))#, textvariable=strVar)
for item in self.items:
self.masters.insert(tkinter.END, item)
示例5: addLine
# 需要导入模块: import tkinter [as 别名]
# 或者: from tkinter import StringVar [as 别名]
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")
示例6: create_variables
# 需要导入模块: import tkinter [as 别名]
# 或者: from tkinter import StringVar [as 别名]
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
示例7: load_settings
# 需要导入模块: import tkinter [as 别名]
# 或者: from tkinter import StringVar [as 别名]
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)
示例8: __init__
# 需要导入模块: import tkinter [as 别名]
# 或者: from tkinter import StringVar [as 别名]
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))
示例9: __init__
# 需要导入模块: import tkinter [as 别名]
# 或者: from tkinter import StringVar [as 别名]
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')
)
示例10: __init__
# 需要导入模块: import tkinter [as 别名]
# 或者: from tkinter import StringVar [as 别名]
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
示例11: __init__
# 需要导入模块: import tkinter [as 别名]
# 或者: from tkinter import StringVar [as 别名]
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
示例12: __init__
# 需要导入模块: import tkinter [as 别名]
# 或者: from tkinter import StringVar [as 别名]
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)
示例13: __init__
# 需要导入模块: import tkinter [as 别名]
# 或者: from tkinter import StringVar [as 别名]
def __init__(self, master, **kwargs):
super().__init__(**kwargs )
self.geometry('350x100')
self.title('Find and Replace')
self.text_to_find = tk.StringVar()
self.text_to_replace_with = tk.StringVar()
top_frame = tk.Frame(self)
middle_frame = tk.Frame(self)
bottom_frame = tk.Frame(self)
find_entry_label = tk.Label(top_frame, text="Find: ")
self.find_entry = ttk.Entry(top_frame, textvar=self.text_to_find)
replace_entry_label = tk.Label(middle_frame, text="Replace: ")
self.replace_entry = ttk.Entry(middle_frame, textvar=self.text_to_replace_with)
self.find_button = ttk.Button(bottom_frame, text="Find", command=self.on_find)
self.replace = ttk.Button(bottom_frame, text="Replace", command=self.on_replace)
self.cancel_button = ttk.Button(bottom_frame, text="Cancel", command=self.destroy)
find_entry_label.pack(side=tk.LEFT, padx=(20, 0))
self.find_entry.pack(side=tk.LEFT, fill=tk.X, expand=1)
replace_entry_label.pack(side=tk.LEFT)
self.replace_entry.pack(side=tk.LEFT, fill=tk.X, expand=1)
self.find_button.pack(side=tk.LEFT, padx=(85, 0))
self.cancel_button.pack(side=tk.RIGHT, padx=(0, 30))
top_frame.pack(side=tk.TOP, expand=1, fill=tk.X, padx=30)
middle_frame.pack(side=tk.TOP, expand=1, fill=tk.X, padx=30)
bottom_frame.pack(side=tk.TOP, expand=1, fill=tk.X)
示例14: on_ctrl_d
# 需要导入模块: import tkinter [as 别名]
# 或者: from tkinter import StringVar [as 别名]
def on_ctrl_d(event=None):
top = tk.Toplevel(win)
top.geometry("200x200")
sv = tk.StringVar()
sv.set("Hover the mouse over me")
label = tk.Label(top, textvar=sv)
label.bind("<Enter>", lambda e, sv=sv: sv.set("Hello mouse!"))
label.bind("<Leave>", lambda e, sv=sv: sv.set("Goodbye mouse!"))
label.pack(expand=1, fill=tk.BOTH)
示例15: __init__
# 需要导入模块: import tkinter [as 别名]
# 或者: from tkinter import StringVar [as 别名]
def __init__(self):
super().__init__()
self.title("Hello Tkinter")
self.label_text = tk.StringVar()
self.label_text.set("Choose One")
self.label = tk.Label(self, textvar=self.label_text)
self.label.pack(fill=tk.BOTH, expand=1, padx=100, pady=30)
hello_button = tk.Button(self, text="Say Hello", command=self.say_hello)
hello_button.pack(side=tk.LEFT, padx=(20, 0), pady=(0, 20))
goodbye_button = tk.Button(self, text="Say Goodbye", command=self.say_goodbye)
goodbye_button.pack(side=tk.RIGHT, padx=(0, 20), pady=(0, 20))