本文整理汇总了Python中tkinter.IntVar.get方法的典型用法代码示例。如果您正苦于以下问题:Python IntVar.get方法的具体用法?Python IntVar.get怎么用?Python IntVar.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tkinter.IntVar
的用法示例。
在下文中一共展示了IntVar.get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_get
# 需要导入模块: from tkinter import IntVar [as 别名]
# 或者: from tkinter.IntVar import get [as 别名]
def test_get(self):
v = IntVar(self.root, 123, "name")
self.assertEqual(123, v.get())
self.root.globalsetvar("name", "345")
self.assertEqual(345, v.get())
self.root.globalsetvar("name", "876.5")
self.assertEqual(876, v.get())
示例2: test_invalid_value
# 需要导入模块: from tkinter import IntVar [as 别名]
# 或者: from tkinter.IntVar import get [as 别名]
def test_invalid_value(self):
v = IntVar(self.root, name="name")
self.root.globalsetvar("name", "value")
with self.assertRaises(ValueError):
v.get()
self.root.globalsetvar("name", "345.0")
with self.assertRaises(ValueError):
v.get()
示例3: FrameKSPObject
# 需要导入模块: from tkinter import IntVar [as 别名]
# 或者: from tkinter.IntVar import get [as 别名]
class FrameKSPObject(Frame):
def __init__(self, master=None):
Frame.__init__(self, master)
self.pack()
frame = Frame(self)
frame.pack()
self.string_var0 = StringVar()
self.string_var1 = StringVar()
self.int_var = IntVar()
self.entry0 = Entry(frame, textvariable=self.string_var0)
self.entry0.pack(side='left')
Entry(frame, textvariable=self.string_var1).pack(side='left')
frame = Frame(self)
frame.pack()
Button(frame, width=8, text='Accept', command=self.accept).pack(side='left')
Button(frame, width=8, text='Cancel', command=self.cancel).pack(side='left')
Button(frame, width=8, text='Delete', command=self.delete).pack(side='left')
def populate(self, kspobject):
self._kspobject = kspobject
self.string_var0.set(kspobject.name)
self.string_var1.set(kspobject.value)
self.int_var.set(kspobject.id_)
def accept(self):
name = self.string_var0.get()
value = self.string_var1.get()
id_ = self.int_var.get()
self.master.master.update_kspobject(name, value, id_)
self.master.destroy()
def cancel(self):
self.master.destroy()
def delete(self):
id_ = self.int_var.get()
self.master.master.delete_kspobject(id_)
self.master.destroy()
示例4: ProgressCheckButton
# 需要导入模块: from tkinter import IntVar [as 别名]
# 或者: from tkinter.IntVar import get [as 别名]
class ProgressCheckButton(Frame, Observable):
def __init__(self, parent, model, index, status_model):
Frame.__init__(self, parent)
Observable.__init__(self)
self.model = model
self.index = index
self.status_model = status_model
self.var = IntVar()
self.var.set(model.get_checked())
self.progress_var = IntVar()
self.progress_status = ProgressStatus.undefined
self.check_button = Checkbutton(self, text=model.get_label, variable=self.var, command=self._check_changed)
self.progress_bar = Progressbar(self, orient='horizontal', mode='indeterminate', variable=self.progress_var)
self.check_button.pack(side=LEFT, fill="both", expand=True)
self.model.add_listener(self._model_changed)
def _model_changed(self, new_status):
model_state = self.model.get_checked()
gui_state = self.var.get()
if model_state is not gui_state:
self.model.set_checked(gui_state)
def refresh_check(self):
if self.status_model.is_checked_force_reload():
self.check_button.select()
else:
self.check_button.deselect()
def is_checked(self):
return self.var.get()
def _progress_status_changed(self, new_status):
self._refresh_progress()
def _refresh_progress(self):
status = self.status_model.get_status()
if not status == self.progress_status:
if status == ProgressStatus.in_progress:
self.progress_bar.pack(side=RIGHT, fill="both", expand=True)
else:
self.progress_bar.pack_forget()
def _check_changed(self):
new_checked = self.var.get()
if new_checked is not self.model.get_checked():
self.model.set_checked(new_checked)
if new_checked is not self.status_model.is_checked():
self._notify(self.index, new_checked)
示例5: PasswordDialog
# 需要导入模块: from tkinter import IntVar [as 别名]
# 或者: from tkinter.IntVar import get [as 别名]
class PasswordDialog(Dialog):
def __init__(self, title, prompt, parent):
self.prompt = prompt
Dialog.__init__(self, parent, title)
def body(self, master):
from tkinter import Label
from tkinter import Entry
from tkinter import Checkbutton
from tkinter import IntVar
from tkinter import W
self.checkVar = IntVar()
Label(master, text=self.prompt).grid(row=0, sticky=W)
self.e1 = Entry(master)
self.e1.grid(row=0, column=1)
self.cb = Checkbutton(master, text="Save to keychain", variable=self.checkVar)
self.cb.pack()
self.cb.grid(row=1, columnspan=2, sticky=W)
self.e1.configure(show='*')
def apply(self):
self.result = (self.e1.get(), self.checkVar.get() == 1)
示例6: DlgLogin
# 需要导入模块: from tkinter import IntVar [as 别名]
# 或者: from tkinter.IntVar import get [as 别名]
class DlgLogin(Dialog):
def body(self, master, cfg={}):
"place user dialog widgets"
self.config = cfg
self.config["OK button"] = False
self.site = StringVar()
self.site.set(cfg.get("site", ""))
self.login = StringVar()
self.login.set(cfg.get("user", ""))
self.password = StringVar()
self.password.set(str(cfg.get("password", "")))
site = Entry(master, width=15, textvariable=self.site)
site.grid(column=1, row=0, sticky="e")
Label(master, text=_("Site:")).grid(column=0, row=0, sticky="w")
loge = Entry(master, width=15, textvariable=self.login)
loge.grid(column=1, row=1, sticky="e")
Label(master, text=_("Username:")).grid(column=0, row=1, sticky="w")
pase = Entry(master, width=15, textvariable=self.password, show="*")
pase.grid(column=1, row=2, sticky="e")
Label(master, text=_("Password:")).grid(column=0, row=2, sticky="w")
self.to_remember = IntVar()
self.to_remember.set(cfg.get("remember_passwd", 1))
chk1 = Checkbutton(master, text="Remember",
variable=self.to_remember)
chk1.grid(column=0, row=3, sticky="w", columnspan=2)
self.resizable(width=0, height=0)
return loge
def apply(self):
"On ok button pressed"
self.config["remember_passwd"] = self.to_remember.get()
self.config["site"] = self.site.get()
self.config["user"] = self.login.get()
self.config["password"].set_password(self.password.get())
self.config["OK button"] = True
示例7: Example
# 需要导入模块: from tkinter import IntVar [as 别名]
# 或者: from tkinter.IntVar import get [as 别名]
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=1)
self.var = IntVar()
cb = Checkbutton(self, text="Show title",
variable=self.var, command=self.onClick)
cb.select()
cb.place(x=50, y=50)
def onClick(self):
if self.var.get() == 1:
self.master.title("Checkbutton")
else:
self.master.title("-")
示例8: highlight_pattern
# 需要导入模块: from tkinter import IntVar [as 别名]
# 或者: from tkinter.IntVar import get [as 别名]
def highlight_pattern(self, pattern, tag, start="1.0", end="end",
regexp=False):
start = self.index(start)
end = self.index(end)
self.mark_set("matchStart", start)
self.mark_set("matchEnd", start)
self.mark_set("searchLimit", end)
count = IntVar()
while True:
index = self.search(pattern, "matchEnd","searchLimit",
count=count, regexp=regexp)
if index == "": break
if count.get() == 0: break
self.mark_set("matchStart", index)
self.mark_set("matchEnd", "%s+%sc" % (index, count.get()))
self.tag_add(tag, "matchStart", "matchEnd")
示例9: MainMenu
# 需要导入模块: from tkinter import IntVar [as 别名]
# 或者: from tkinter.IntVar import get [as 别名]
class MainMenu():
def main(self):
'''Function to run on game start'''
self.mainMenu=Tk()
self.mainMenu.geometry('200x300+200+200')
self.mainMenu.title("Minesweeper")
playButton=Button(self.mainMenu,text='Play',command=lambda:self.startPlay(None))
self.height= IntVar()
self.width= IntVar()
self.minesAmount= IntVar()
self.height.set(10)
self.width.set(10)
self.minesAmount.set(10)
playButton.pack()
xSlider=Scale(self.mainMenu,orient='horizontal',length=150,width=15,label='Height',sliderlength=20,from_=1,to=15,tickinterval=0,variable=self.height).pack()
ySlider=Scale(self.mainMenu,orient='horizontal',length=150,width=15,label='Width',sliderlength=20,from_=1,to=15,tickinterval=0,variable=self.width).pack()
minesSlider=Scale(self.mainMenu,orient='horizontal',length=150,width=15,label='Mines',sliderlength=20,from_=0,to=15*15-1,tickinterval=0,variable=self.minesAmount).pack()
aboutButton=Button(self.mainMenu,text='About',command=self.about)
quitButton=Button(self.mainMenu,text='Quit',command=self.quitApp)
aboutButton.pack()
quitButton.pack()
def startPlay(self,event):
play=Play()
minesAmount=self.minesAmount.get()
height=self.height.get()
width=self.width.get()
if minesAmount>width*height-1:
messagebox.showerror(title='Error',message="Amount of mines can't be bigger than total size of the field. Plese try again.")
return
self.mainMenu.destroy()
play.StartGame(minesAmount,height,width)
def about(self):
messagebox.showinfo(title='About',message='Author:Marcel Salmič.')
def quitApp(self):
self.mainMenu.destroy()
示例10: Checkbox
# 需要导入模块: from tkinter import IntVar [as 别名]
# 或者: from tkinter.IntVar import get [as 别名]
class Checkbox(Checkbutton):
def __init__(self, master, text, default=None, **args):
self.var = IntVar()
Checkbutton.__init__(self, master, text=text, variable=self.var, **args)
if default is not None:
self.var.set(default)
def get(self):
return self.var.get()
示例11: ValCheckbutton
# 需要导入模块: from tkinter import IntVar [as 别名]
# 或者: from tkinter.IntVar import get [as 别名]
class ValCheckbutton(Checkbutton):
def __init__(self, master, **kw):
self.intVal = IntVar()
Checkbutton.__init__(self, master, var=self.intVal, **kw)
def setVal(self, val):
if bool(val):
self.select()
else:
self.deselect()
def getVal(self):
return bool(self.intVal.get())
示例12: ConfigDialog
# 需要导入模块: from tkinter import IntVar [as 别名]
# 或者: from tkinter.IntVar import get [as 别名]
class ConfigDialog(Toplevel):
'''Every instance of the TkTimer needs a Tk widget to call the after method.
If no widget is provided, the TkTimer will create this ConfigDialog,
and use its Toplevel's after method.
'''
def __init__(self, *args, **kwargs):
timer = kwargs.pop('timer')
self.__timer = timer
super().__init__(*args, **kwargs)
interval = LabeledEntry(self)
interval.label_text = 'Interval (ms)'
interval.entry_text = str(timer.interval)
interval.entry_width = 5
interval.pack(side='top')
self.interval = interval
self.active = IntVar(timer.active)
Checkbutton(self, text='Activate', variable=self.active, command=self._on_active_button_click).pack(side='top')
Button(self, text='OK', command=self._on_ok_button_click).pack(side='top')
def hide(): self.visible = False
self.protocol('WM_DELETE_WINDOW', hide)
self.__visible = True
self.visible = False
def _on_active_button_click(self):
self.__timer.active = self.active.get()
def _on_ok_button_click(self):
self.__timer.interval = self.interval.get_int()
@property
def visible(self):
return self.__visible
@visible.setter
def visible(self, val):
self.__visible = val
if val:
self.update()
self.deiconify()
else:
self.withdraw()
示例13: ProgressListBoxItem
# 需要导入模块: from tkinter import IntVar [as 别名]
# 或者: from tkinter.IntVar import get [as 别名]
class ProgressListBoxItem(Frame, Observable):
def __init__(self, parent, model):
Frame.__init__(self, parent)
Observable.__init__(self)
self._model = model
# Create variables and initialise to zero
self._checked_var = IntVar()
self._progress_var = IntVar()
self._checked_var.set(0)
self._progress_var.set(0)
self._current_gui_checked_state = CheckStatus.undefined
self._current_gui_progress_state = ProgressStatus.undefined
self.check_button = Checkbutton(self, text=model.get_label(), variable=self._checked_var, command=self._user_check_changed)
self.progress_bar = Progressbar(self, orient='horizontal', mode='indeterminate', variable=self._progress_var)
self.check_button.pack(side=LEFT, fill="both", expand=True)
self._update()
self._model.add_listener(self._model_changed)
def _model_changed(self):
self.update()
def _update(self):
# Update check status
model_check_state = self._model.get_check_status()
if model_check_state is not self._current_gui_checked_state:
self._current_gui_checked_state = model_check_state
# if self.status_model.is_checked_force_reload():
if model_check_state:
self.check_button.select()
else:
self.check_button.deselect()
# Update progress status
model_progress_state = self._model.get_progress_status
if not model_progress_state == self._current_gui_progress_state:
self._current_gui_progress_state = model_progress_state
if model_progress_state == ProgressStatus.in_progress:
self.progress_bar.pack(side=RIGHT, fill="both", expand=True)
else:
self.progress_bar.pack_forget()
def _user_check_changed(self):
new_checked = self._checked_var.get()
if new_checked is not self._model.get_check_status():
self._model.manual_set_checked(new_checked)
示例14: highlight_pattern
# 需要导入模块: from tkinter import IntVar [as 别名]
# 或者: from tkinter.IntVar import get [as 别名]
def highlight_pattern(self, pattern, tag, start="1.0", end="end", regexp=False):
'''Apply the given tag to all text that matches the given pattern
If 'regexp' is set to True, pattern will be treated as a regular expression
'''
start = self.index(start)
end = self.index(end)
self.mark_set("matchStart",start)
self.mark_set("matchEnd",start)
self.mark_set("searchLimit", end)
count = IntVar()
while True:
index = self.search(pattern, "matchEnd","searchLimit", count=count, regexp=regexp)
if index == "": break
self.mark_set("matchStart", index)
self.mark_set("matchEnd", "%s+%sc" % (index,count.get()))
self.tag_add(tag, "matchStart","matchEnd")
示例15: test_default
# 需要导入模块: from tkinter import IntVar [as 别名]
# 或者: from tkinter.IntVar import get [as 别名]
def test_default(self):
v = IntVar(self.root)
self.assertEqual(0, v.get())