本文整理汇总了Python中Tkinter.BooleanVar类的典型用法代码示例。如果您正苦于以下问题:Python BooleanVar类的具体用法?Python BooleanVar怎么用?Python BooleanVar使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了BooleanVar类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: CreateOldSeparatorMenu
def CreateOldSeparatorMenu(self):
self.oldSeparatorMenu = Menu(self.optionsMenu, tearoff=0)
self.oldSpacesButton = BooleanVar()
self.oldUnderscoresButton = BooleanVar()
self.oldCamelcaseButton = BooleanVar()
self.oldPeriodButton = BooleanVar()
self.oldSeparatorMenu.add_checkbutton(label="Spaces", onvalue=True, offvalue=False,
variable=self.oldSpacesButton)
self.oldSpacesButton.set(True)
self.oldSeparatorMenu.add_checkbutton(label="Underscores", onvalue=True, offvalue=False,
variable=self.oldUnderscoresButton)
self.oldUnderscoresButton.set(True)
#self.oldSeparatorMenu.add_command(label="Custom Separator", command=self.customSeparatorFrame)
self.oldSeparatorMenu.add_checkbutton(label="CamelCase", onvalue=True, offvalue=False,
variable=self.oldCamelcaseButton)
self.oldSeparatorMenu.add_checkbutton(label="Period", onvalue=True, offvalue=False,
variable=self.oldPeriodButton)
self.optionsMenu.add_cascade(label="Old Separator", menu=self.oldSeparatorMenu)
示例2: MenuItem
class MenuItem(object):
def __init__(self, menu, title, **kwargs):
self._menu = menu
if kwargs.get('checkbox'):
# Checkbox menu item
self._checkvar = BooleanVar()
self._checkvar.set(kwargs.get('checked', False))
self._menu._ctrl.add_checkbutton(label=title, command=self._on_check, variable=self._checkvar)
else:
# NOTE: For whatever reason, lambdas do not work in this case...
self._menu._ctrl.add_command(label=title, command=self._on_click)
if kwargs.get('on_click'):
self.on_click = kwargs['on_click']
def _on_check(self):
"""Handler for keeping on_click virtual with checkbox option"""
self.on_click(self._checkvar.get())
def _on_click(self):
"""Handler for keeping on_click virtual"""
self.on_click()
def on_click(self):
pass
def __exit__(self, *args):
pass
def __enter__(self, *args):
return self
示例3: test_invalid_value_domain
def test_invalid_value_domain(self):
v = BooleanVar(self.root, name='name')
self.root.globalsetvar('name', 'value')
with self.assertRaises(TclError):
v.get()
self.root.globalsetvar('name', '1.0')
with self.assertRaises(TclError):
v.get()
示例4: addSubCheckbuttons
def addSubCheckbuttons(self):
self.affectSubfolders = BooleanVar()
self.cleanFolderNames = BooleanVar()
self.optionsMenu.add_checkbutton(label="Affect Subfolders", onvalue=True, offvalue=False, variable=self.affectSubfolders)
self.optionsMenu.add_checkbutton(label="Clean Folder Names", onvalue=True, offvalue=False, variable=self.cleanFolderNames)
self.affectSubfolders.set(True)
self.cleanFolderNames.set(True)
示例5: __init__
def __init__(self, root):
self.root = root
# State shared by search, replace, and grep;
# the search dialogs bind these to UI elements.
self.patvar = StringVar(root) # search pattern
self.revar = BooleanVar(root) # regular expression?
self.casevar = BooleanVar(root) # match case?
self.wordvar = BooleanVar(root) # match whole word?
self.wrapvar = BooleanVar(root) # wrap around buffer?
self.wrapvar.set(1) # (on by default)
self.backvar = BooleanVar(root) # search backwards?
示例6: __init__
def __init__(self, root):
'''Initialize Variables that save search state.
The dialogs bind these to the UI elements present in the dialogs.
'''
self.root = root # need for report_error()
self.patvar = StringVar(root, '') # search pattern
self.revar = BooleanVar(root, False) # regular expression?
self.casevar = BooleanVar(root, False) # match case?
self.wordvar = BooleanVar(root, False) # match whole word?
self.wrapvar = BooleanVar(root, True) # wrap around buffer?
self.backvar = BooleanVar(root, False) # search backwards?
示例7: __init__
def __init__(self, root):
"""Initialize Variables that save search state.
The dialogs bind these to the UI elements present in the dialogs.
"""
self.root = root
self.patvar = StringVar(root, '')
self.revar = BooleanVar(root, False)
self.casevar = BooleanVar(root, False)
self.wordvar = BooleanVar(root, False)
self.wrapvar = BooleanVar(root, True)
self.backvar = BooleanVar(root, False)
示例8: login_gui
def login_gui(username, password):
def get_login(evt=None):
temp_username = username_holder.get()
temp_password = password_holder.get()
if remember_login_holder.get():
logon_file = open("dep.dat", "w")
logon_file.write(encodestring(temp_username+" "+temp_password))
logon_file.close()
elif os.path.isfile("dep.dat"):
os.remove("dep.dat")
login_tk.destroy()
wrap.login(temp_username, temp_password)
overview_gui()
return
def on_checkbox_flip():
if remember_login_holder.get():
logon_file = open("dep.dat", "w")
logon_file.write(encodestring(username_holder.get()+" "+password_holder.get()))
logon_file.close()
else:
if os.path.isfile("dep.dat"):
os.remove("dep.dat")
return
login_tk = Tk()
login_tk.title("Login Window")
Label(login_tk, text="Login to GradeSpeed").pack(padx=50, pady=(10, 5))
Label(login_tk, text="Username:").pack(padx=50, pady=(5, 0))
username_holder = StringVar()
username_holder.set(username)
username_field = Entry(login_tk, textvariable=username_holder)
username_field.pack(padx=50, pady=(0, 5))
username_field.bind("<Key-Return>", get_login)
Label(login_tk, text="Password:").pack(padx=50, pady=(5, 0))
password_holder = StringVar()
password_holder.set(password)
password_field = Entry(login_tk, textvariable=password_holder, show="*")
password_field.pack(padx=50, pady=(0, 5))
password_field.bind("<Key-Return>", get_login)
remember_login_holder = BooleanVar()
remember_login_holder.set(len(username) > 0)
login_frame = Frame(login_tk)
Checkbutton(login_frame, text="Remember Logon", var=remember_login_holder, command=on_checkbox_flip).pack()
login_frame.pack(pady=5)
Button(text="Login", command=get_login).pack(padx=50, pady=(5, 10))
center_gui(login_tk)
login_tk.mainloop()
示例9: Example
class Example(Frame):
def __init__(self, parent):
Frame.__init__(self, parent)
self.parent = parent
self.initUI()
def initUI(self):
self.parent.title("Checkbutton")
self.pack(fill=BOTH, expand=True)
self.var = BooleanVar()
cb = Checkbutton(self, text="Show title",
variable=self.var, command=self.onClick)
cb.select()
cb.place(x=50, y=30)
def onClick(self):
if self.var.get() == True:
self.master.title("Checkbutton")
else:
self.master.title("")
示例10: MeasureFrame
class MeasureFrame(LabelFrame):
def __init__(self, master, tracker, text="Measuring", *args, **kwargs):
LabelFrame.__init__(self, master, text=text, *args, **kwargs)
self.tracker = tracker
self.config_frame = NamedEntryFrame(self, (OBS_INTERVAL,
NUM_SAMPLES,
NUM_OBSS),
parsers={OBS_INTERVAL: float,
NUM_SAMPLES: int,
NUM_OBSS: int})
self.config_frame.grid()
self.save_frame = LabelFrame(self, text="Saving")
self.dest_selector = FileSelectionFrame(self.save_frame,
ask_mode="save")
self.dest_selector.grid(row=0, column=0, columnspan=2)
self.save_button = Button(self.save_frame, text="Save",
command=bg_caller(self.save))
self.save_button.grid(row=1, column=0)
self.appending_var = BooleanVar()
self.append_checkbutton = Checkbutton(self.save_frame, text="Append",
variable=self.appending_var)
self.append_checkbutton.grid(row=1, column=1)
self.save_frame.grid()
def measure(self, only_accurate=True):
try:
interval = self.config_frame.get(OBS_INTERVAL)
samples = self.config_frame.get(NUM_SAMPLES)
num_obss = self.config_frame.get(NUM_OBSS)
except ValueError:
logger.error("Could not parse input fields.")
data = self.tracker.measure(observation_interval=interval,
samples_per_observation=samples,
number_of_observations=num_obss)
if only_accurate:
accurate_data = [point for point in data
if point.status == point.DATA_ACCURATE]
num_invalid = len(data) - len(accurate_data)
if num_invalid > 0:
logger.warning("Hiding {} inaccurate data points."
.format(num_invalid))
return accurate_data
else:
return data
def save(self, only_accurate=True):
dest = self.dest_selector.path_var.get()
if not dest:
logger.error("Must select a destination file.")
return
data = self.measure(only_accurate=only_accurate)
w = csv.writer(open(dest, 'a' if self.appending_var.get() else 'w'))
for point in data:
w.writerow((point.time, point.position.r,
point.position.theta, point.position.phi))
logger.info("Saved measurements into {!r}".format(dest))
示例11: createNewSeparatorMenu
def createNewSeparatorMenu(self):
self.newSeparatorMenu = Menu(self.optionsMenu, tearoff=0)
self.spacesButton = BooleanVar()
self.underscoresButton = BooleanVar()
self.camelcaseButton = BooleanVar()
self.periodButton = BooleanVar()
self.newSeparatorMenu.add_checkbutton(label="Spaces", onvalue=True, offvalue=False,
variable=self.spacesButton, command=self.ToggleNonSpacesOff)
self.spacesButton.set(True)
self.newSeparatorMenu.add_checkbutton(label="Underscores", onvalue=True, offvalue=False,
variable=self.underscoresButton, command=self.ToggleNonUnderscoresOff)
self.newSeparatorMenu.add_command(label="Custom Separator", command=self.customSeparatorFrame)
self.newSeparatorMenu.add_checkbutton(label="CamelCase", onvalue=True, offvalue=False,
variable=self.camelcaseButton, command=self.ToggleNonCamelCaseOff)
self.newSeparatorMenu.add_checkbutton(label="Period", onvalue=True, offvalue=False,
variable=self.periodButton, command=self.ToggleNonPeriodOff)
self.optionsMenu.add_cascade(label="New Separator", menu=self.newSeparatorMenu)
示例12: __init__
def __init__( self, parent, defaultfont=None, showstyles=None ):
self._family = StringVar( value='Century Schoolbook L')
self._sizeString = StringVar( value='20' )
self._weight = StringVar( value=tkFont.NORMAL )
self._slant = StringVar( value=tkFont.ROMAN )
self._isUnderline = BooleanVar( value=False )
self._isOverstrike = BooleanVar( value=False )
if defaultfont:
self._initialize( defaultfont )
self._currentFont = tkFont.Font( font=self.getFontTuple() )
self._showStyles = showstyles
self.sampleText = None
tkSimpleDialog.Dialog.__init__( self, parent, 'Font Chooser' )
示例13: createBreakUpByMenu
def createBreakUpByMenu(self):
self.delimitersMenu = Menu(self.optionsMenu, tearoff=0)
self.breakUpByBraces = BooleanVar()
self.breakUpByParens = BooleanVar()
self.breakUpByBrackets = BooleanVar()
self.breakUpByCamelCase = BooleanVar()
self.breakUpByParens.set(True)
self.breakUpByBrackets.set(True)
self.delimitersMenu.add_checkbutton(label="Braces", onvalue=True, offvalue=False, variable=self.breakUpByBraces)
self.delimitersMenu.add_checkbutton(label="Parentheses", onvalue=True, offvalue=False, variable=self.breakUpByParens)
self.delimitersMenu.add_checkbutton(label="Brackets", onvalue=True, offvalue=False, variable=self.breakUpByBrackets)
self.delimitersMenu.add_checkbutton(label="CamelCase", onvalue=True, offvalue=False, variable=self.breakUpByCamelCase)
self.optionsMenu.add_cascade(label="Delimiters", menu=self.delimitersMenu)
示例14: test_get
def test_get(self):
v = BooleanVar(self.root, True, "name")
self.assertIs(v.get(), True)
self.root.globalsetvar("name", "0")
self.assertIs(v.get(), False)
self.root.globalsetvar("name", 42 if self.root.wantobjects() else 1)
self.assertIs(v.get(), True)
self.root.globalsetvar("name", 0)
self.assertIs(v.get(), False)
self.root.globalsetvar("name", 42L if self.root.wantobjects() else 1L)
self.assertIs(v.get(), True)
self.root.globalsetvar("name", 0L)
self.assertIs(v.get(), False)
self.root.globalsetvar("name", "on")
self.assertIs(v.get(), True)
self.root.globalsetvar("name", u"0")
self.assertIs(v.get(), False)
self.root.globalsetvar("name", u"on")
self.assertIs(v.get(), True)
示例15: initUI
def initUI(self):
self.parent.title("CheckButton")
self.pack(fill=BOTH,expand=True)
self.var = BooleanVar()
self.var.set(False)
chbt = Checkbutton(self,text="Show Title",
variable=self.var,command=self.onClick)
#chbt.select()
chbt.place(x=50,y=50)