python中stringvar的用法_Python tkinter.StringVar方法代码示例

本文整理汇总了Python中tkinter.StringVar方法的典型用法代码示例。如果您正苦于以下问题:Python tkinter.StringVar方法的具体用法?Python tkinter.StringVar怎么用?Python tkinter.StringVar使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在模块tkinter的用法示例。

在下文中一共展示了tkinter.StringVar方法的18个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: __init__

​点赞 6

# 需要导入模块: 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

)

开发者ID:winkidney,项目名称:PickTrue,代码行数:27,

示例2: __init__

​点赞 6

# 需要导入模块: 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()

开发者ID:liucaide,项目名称:Andromeda,代码行数:25,

示例3: __init__

​点赞 6

# 需要导入模块: 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)

开发者ID:YoannDupont,项目名称:SEM,代码行数:21,

示例4: addLine

​点赞 6

# 需要导入模块: 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")

开发者ID:ArtificialQualia,项目名称:PyEveLiveDPS,代码行数:23,

示例5: create_variables

​点赞 6

# 需要导入模块: 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

开发者ID:lovexiaov,项目名称:python-in-practice,代码行数:20,

示例6: __init__

​点赞 6

# 需要导入模块: 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)

开发者ID:lovexiaov,项目名称:python-in-practice,代码行数:19,

示例7: load_settings

​点赞 6

# 需要导入模块: 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)

开发者ID:PacktPublishing,项目名称:Python-GUI-Programming-with-Tkinter,代码行数:21,

示例8: __init__

​点赞 6

# 需要导入模块: 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))

开发者ID:PacktPublishing,项目名称:Python-GUI-Programming-with-Tkinter,代码行数:24,

示例9: __init__

​点赞 6

# 需要导入模块: 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')

)

开发者ID:PacktPublishing,项目名称:Python-GUI-Programming-with-Tkinter,代码行数:24,

示例10: __init__

​点赞 6

# 需要导入模块: 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

开发者ID:PacktPublishing,项目名称:Python-GUI-Programming-with-Tkinter,代码行数:27,

示例11: __init__

​点赞 6

# 需要导入模块: 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

开发者ID:PacktPublishing,项目名称:Python-GUI-Programming-with-Tkinter,代码行数:26,

示例12: __init__

​点赞 6

# 需要导入模块: 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)

开发者ID:PacktPublishing,项目名称:Python-GUI-Programming-with-Tkinter,代码行数:21,

示例13: __init__

​点赞 5

# 需要导入模块: 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)

开发者ID:PacktPublishing,项目名称:Tkinter-GUI-Programming-by-Example,代码行数:37,

示例14: on_ctrl_d

​点赞 5

# 需要导入模块: 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("", lambda e, sv=sv: sv.set("Hello mouse!"))

label.bind("", lambda e, sv=sv: sv.set("Goodbye mouse!"))

label.pack(expand=1, fill=tk.BOTH)

开发者ID:PacktPublishing,项目名称:Tkinter-GUI-Programming-by-Example,代码行数:11,

示例15: __init__

​点赞 5

# 需要导入模块: 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))

开发者ID:PacktPublishing,项目名称:Tkinter-GUI-Programming-by-Example,代码行数:16,

示例16: __init__

​点赞 5

# 需要导入模块: import tkinter [as 别名]

# 或者: from tkinter import StringVar [as 别名]

def __init__(self, master):

# More advanced as compared to regular buttons

# Check buttons can also store binary values

self.checkbutton = ttk.Checkbutton(master, text = 'Check Me!')

self.checkbutton.pack()

self.label = ttk.Label(master, text = 'Ready!! Nothing has happened yet.')

self.label.pack()

# Tkinter variable classes

# self.boolvar = tk.BooleanVar() # boolean type variable of tk

# self.dblvar = tk.DoubleVar() # double type variable of tk

# self.intvar = tk.IntVar() # int type variable of tk

self.checkme = tk.StringVar() # string type variable of tk

self.checkme.set('NULL') # set value for string type tkinter variable

print('Current value of checkme variable is \'{}\''.format(self.checkme.get()))

# setting of binary value for check button: 1. onvaalue and 2. offvalue

self.checkbutton.config(variable = self.checkme, onvalue = 'I am checked!!', offvalue = 'Waiting for someone to check me!')

self.checkbutton.config(command = self.oncheckme)

# creating another tkinter string type variable - StringVar

self.papertype = tk.StringVar() # created a variable

self.radiobutton1 = ttk.Radiobutton(master, text = 'Paper1', variable=self.papertype, value = 'Robotics Research')

self.radiobutton1.config(command = self.onselectradio)

self.radiobutton1.pack()

self.radiobutton2 = ttk.Radiobutton(master, text = 'Paper2', variable=self.papertype, value = 'Solid Mechanics Research')

self.radiobutton2.config(command = self.onselectradio)

self.radiobutton2.pack()

self.radiobutton3 = ttk.Radiobutton(master, text = 'Paper3', variable=self.papertype, value = 'Biology Research')

self.radiobutton3.config(command = self.onselectradio)

self.radiobutton3.pack()

self.radiobutton4 = ttk.Radiobutton(master, text = 'Paper4', variable=self.papertype, value = 'SPAM Research')

self.radiobutton4.config(command = self.onselectradio)

self.radiobutton4.pack()

self.radiobutton5 = ttk.Radiobutton(master, text = 'Change Checkme text', variable=self.papertype, value = 'Radio Checkme Selected')

self.radiobutton5.pack()

self.radiobutton5.config(command = self.onradiobuttonselect)

开发者ID:adipandas,项目名称:python-gui-demos,代码行数:40,

示例17: __init__

​点赞 5

# 需要导入模块: import tkinter [as 别名]

# 或者: from tkinter import StringVar [as 别名]

def __init__(self, master):

self.label = ttk.Label(master, text='Enter the text below')

self.label.pack()

self.entry = ttk.Entry(master, width = 30) # number of characters along the width

self.entry.pack()

self.button = ttk.Button(master, text = "Get Entry")

self.button.pack()

self.tkstrvar = tk.StringVar() # create tk string variable

self.tkstrvar.set('Nothing is done yet!') # set the value of tk string variable

self.button.config(command = self.getEntry)

self.msg = ttk.Label(master, text = self.tkstrvar.get()) # get the value of string variable

self.msg.pack()

self.btn1 = ttk.Button(master, text='Delete the entry', command = self.btn1func)

self.btn1.pack()

self.crypt = tk.StringVar()

self.crypt.set('Encrypt')

self.btn2 = ttk.Button(master, text = "{} Text in Entry Field".format(self.crypt.get()), command = self.changecrypt)

self.btn2.pack()

#self.entryText = ttk.Entry(master, width=30)

ttk.Button(master, text = 'Disable Entry Field', command = self.btn3func).pack()

ttk.Button(master, text = 'Enable Entry Field', command = self.btn4func).pack()

ttk.Button(master, text = 'Readonly Entry Field', command = self.btn5func).pack()

ttk.Button(master, text = 'Edit Entry Field', command = self.btn6func).pack()

开发者ID:adipandas,项目名称:python-gui-demos,代码行数:31,

示例18: __init__

​点赞 5

# 需要导入模块: import tkinter [as 别名]

# 或者: from tkinter import StringVar [as 别名]

def __init__(self, master):

ttk.Label(master, text = "PROGRESS CONTROL").pack()

# Inderterminant Progressbar

ttk.Label(master, text = 'Inderterminant Progress').pack()

self.prgrsbr_indtr = ttk.Progressbar(master, orient = tk.HORIZONTAL, length = 300, mode = 'indeterminate')

self.prgrsbr_indtr.pack()

self.checkpbi = tk.StringVar()

self.checkpbi.set("Start")

# Button

self.btn1 = ttk.Button(master, text = "{} Inderterminant Progress Bar".format(self.checkpbi.get()), command = self.btn1cmd)

self.btn1.pack()

# Derterminant progress

ttk.Label(master, text = 'Derterminant Progress').pack()

self.prgrsbr_dtr = ttk.Progressbar(master, orient=tk.HORIZONTAL, length = 300, mode = 'determinate')

self.prgrsbr_dtr.pack()

self.prgrsbr_dtr.config(maximum = 10.0, value = 2.0) # notice both these properties have float values

# Button

ttk.Button(master, text = 'Reset Progress Bar to zero', command = self.resetProgressBarVal).pack()

# Button

ttk.Button(master, text = 'Increase Progress Bar by 2', command = self.shift2ProgressBarVal).pack()

# create double variable

self.prgrsBrVal = tk.DoubleVar()

self.prgrsbr_dtr.config(variable = self.prgrsBrVal) # set variable property of progressbar to look at DoubleVar()

# Scale widget

self.scalebar = ttk.Scale(master, orient = tk.HORIZONTAL, length = 400, variable=self.prgrsBrVal, from_ = 0.0, to= 10.0)

self.scalebar.pack()

# Label to display current value of scalebar

ttk.Label(master, text = "Current value of Progress Bar is as below:").pack()

self.scalebar_label = ttk.Label(master, textvariable = self.prgrsBrVal)

self.scalebar_label.pack()

开发者ID:adipandas,项目名称:python-gui-demos,代码行数:41,

注:本文中的tkinter.StringVar方法示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。

你可能感兴趣的:(python中stringvar的用法_Python tkinter.StringVar方法代码示例)