本文整理汇总了Python中tkinter.ttk.Label.config方法的典型用法代码示例。如果您正苦于以下问题:Python Label.config方法的具体用法?Python Label.config怎么用?Python Label.config使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tkinter.ttk.Label
的用法示例。
在下文中一共展示了Label.config方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: DialogPackageManager
# 需要导入模块: from tkinter.ttk import Label [as 别名]
# 或者: from tkinter.ttk.Label import config [as 别名]
class DialogPackageManager(Toplevel):
def __init__(self, mainWin, packageNamesWithNewerFileDates):
super(DialogPackageManager, self).__init__(mainWin.parent)
self.ENABLE = _("Enable")
self.DISABLE = _("Disable")
self.parent = mainWin.parent
self.cntlr = mainWin
# copy plugins for temporary display
self.packagesConfig = PackageManager.packagesConfig
self.packagesConfigChanged = False
self.packageNamesWithNewerFileDates = packageNamesWithNewerFileDates
parentGeometry = re.match("(\d+)x(\d+)[+]?([-]?\d+)[+]?([-]?\d+)", self.parent.geometry())
dialogX = int(parentGeometry.group(3))
dialogY = int(parentGeometry.group(4))
self.title(_("Taxonomy Packages Manager"))
frame = Frame(self)
# left button frame
buttonFrame = Frame(frame, width=40)
buttonFrame.columnconfigure(0, weight=1)
addLabel = Label(buttonFrame, text=_("Find taxonomy packages:"), wraplength=64, justify="center")
addLocalButton = Button(buttonFrame, text=_("Locally"), command=self.findLocally)
ToolTip(addLocalButton, text=_("File chooser allows selecting taxonomy packages to add (or reload), from the local file system. "
"Select either a taxonomy package zip file, or a taxonomy manifest (.taxonomyPackage.xml) within an unzipped taxonomy package. "), wraplength=240)
addWebButton = Button(buttonFrame, text=_("On Web"), command=self.findOnWeb)
ToolTip(addWebButton, text=_("Dialog to enter URL full path to load (or reload) package, from the web or local file system. "
"URL may be either a taxonomy package zip file, or a taxonomy manifest (.taxonomyPackage.xml) within an unzipped taxonomy package. "), wraplength=240)
manifestNameButton = Button(buttonFrame, text=_("Manifest"), command=self.manifestName)
ToolTip(manifestNameButton, text=_("Provide non-standard archive manifest file name pattern (e.g., *taxonomyPackage.xml). "
"Uses unix file name pattern matching. "
"Multiple manifest files are supported in archive (such as oasis catalogs). "
"(Replaces search for either .taxonomyPackage.xml or catalog.xml). "), wraplength=240)
self.manifestNamePattern = ""
addLabel.grid(row=0, column=0, pady=4)
addLocalButton.grid(row=1, column=0, pady=4)
addWebButton.grid(row=2, column=0, pady=4)
manifestNameButton.grid(row=3, column=0, pady=4)
buttonFrame.grid(row=0, column=0, rowspan=3, sticky=(N, S, W), padx=3, pady=3)
# right tree frame (packages already known to arelle)
packagesFrame = Frame(frame, width=700)
vScrollbar = Scrollbar(packagesFrame, orient=VERTICAL)
hScrollbar = Scrollbar(packagesFrame, orient=HORIZONTAL)
self.packagesView = Treeview(packagesFrame, xscrollcommand=hScrollbar.set, yscrollcommand=vScrollbar.set, height=7)
self.packagesView.grid(row=0, column=0, sticky=(N, S, E, W))
self.packagesView.bind('<<TreeviewSelect>>', self.packageSelect)
hScrollbar["command"] = self.packagesView.xview
hScrollbar.grid(row=1, column=0, sticky=(E,W))
vScrollbar["command"] = self.packagesView.yview
vScrollbar.grid(row=0, column=1, sticky=(N,S))
packagesFrame.columnconfigure(0, weight=1)
packagesFrame.rowconfigure(0, weight=1)
packagesFrame.grid(row=0, column=1, columnspan=4, sticky=(N, S, E, W), padx=3, pady=3)
self.packagesView.focus_set()
self.packagesView.column("#0", width=120, anchor="w")
self.packagesView.heading("#0", text=_("Name"))
self.packagesView["columns"] = ("ver", "status", "date", "update", "descr")
self.packagesView.column("ver", width=150, anchor="w", stretch=False)
self.packagesView.heading("ver", text=_("Version"))
self.packagesView.column("status", width=50, anchor="w", stretch=False)
self.packagesView.heading("status", text=_("Status"))
self.packagesView.column("date", width=170, anchor="w", stretch=False)
self.packagesView.heading("date", text=_("File Date"))
self.packagesView.column("update", width=50, anchor="w", stretch=False)
self.packagesView.heading("update", text=_("Update"))
self.packagesView.column("descr", width=200, anchor="w", stretch=False)
self.packagesView.heading("descr", text=_("Description"))
remappingsFrame = Frame(frame)
vScrollbar = Scrollbar(remappingsFrame, orient=VERTICAL)
hScrollbar = Scrollbar(remappingsFrame, orient=HORIZONTAL)
self.remappingsView = Treeview(remappingsFrame, xscrollcommand=hScrollbar.set, yscrollcommand=vScrollbar.set, height=5)
self.remappingsView.grid(row=0, column=0, sticky=(N, S, E, W))
hScrollbar["command"] = self.remappingsView.xview
hScrollbar.grid(row=1, column=0, sticky=(E,W))
vScrollbar["command"] = self.remappingsView.yview
vScrollbar.grid(row=0, column=1, sticky=(N,S))
remappingsFrame.columnconfigure(0, weight=1)
remappingsFrame.rowconfigure(0, weight=1)
remappingsFrame.grid(row=1, column=1, columnspan=4, sticky=(N, S, E, W), padx=3, pady=3)
self.remappingsView.focus_set()
self.remappingsView.column("#0", width=200, anchor="w")
self.remappingsView.heading("#0", text=_("Prefix"))
self.remappingsView["columns"] = ("remapping")
self.remappingsView.column("remapping", width=500, anchor="w", stretch=False)
self.remappingsView.heading("remapping", text=_("Remapping"))
# bottom frame package info details
packageInfoFrame = Frame(frame, width=700)
packageInfoFrame.columnconfigure(1, weight=1)
self.packageNameLabel = Label(packageInfoFrame, wraplength=600, justify="left",
font=font.Font(family='Helvetica', size=12, weight='bold'))
self.packageNameLabel.grid(row=0, column=0, columnspan=6, sticky=W)
#.........这里部分代码省略.........
示例2: DialogPluginManager
# 需要导入模块: from tkinter.ttk import Label [as 别名]
# 或者: from tkinter.ttk.Label import config [as 别名]
class DialogPluginManager(Toplevel):
def __init__(self, mainWin, modulesWithNewerFileDates):
super(DialogPluginManager, self).__init__(mainWin.parent)
self.ENABLE = _("Enable")
self.DISABLE = _("Disable")
self.parent = mainWin.parent
self.cntlr = mainWin
# copy plugins for temporary display
self.pluginConfig = PluginManager.pluginConfig
self.pluginConfigChanged = False
self.uiClassMethodsChanged = False
self.modelClassesChanged = False
self.disclosureSystemTypesChanged = False
self.hostSystemFeaturesChanged = False
self.modulesWithNewerFileDates = modulesWithNewerFileDates
parentGeometry = re.match("(\d+)x(\d+)[+]?([-]?\d+)[+]?([-]?\d+)", self.parent.geometry())
dialogX = int(parentGeometry.group(3))
dialogY = int(parentGeometry.group(4))
self.title(_("Plug-in Manager"))
frame = Frame(self)
# left button frame
buttonFrame = Frame(frame, width=40)
buttonFrame.columnconfigure(0, weight=1)
addLabel = Label(buttonFrame, text=_("Find plug-in modules:"), wraplength=60, justify="center")
addLocalButton = Button(buttonFrame, text=_("Locally"), command=self.findLocally)
ToolTip(addLocalButton, text=_("File chooser allows selecting python module files to add (or reload) plug-ins, from the local file system."), wraplength=240)
addWebButton = Button(buttonFrame, text=_("On Web"), command=self.findOnWeb)
ToolTip(addWebButton, text=_("Dialog to enter URL full path to load (or reload) plug-ins, from the web or local file system."), wraplength=240)
addLabel.grid(row=0, column=0, pady=4)
addLocalButton.grid(row=1, column=0, pady=4)
addWebButton.grid(row=2, column=0, pady=4)
buttonFrame.grid(row=0, column=0, rowspan=2, sticky=(N, S, W), padx=3, pady=3)
# right tree frame (plugins already known to arelle)
modulesFrame = Frame(frame, width=700)
vScrollbar = Scrollbar(modulesFrame, orient=VERTICAL)
hScrollbar = Scrollbar(modulesFrame, orient=HORIZONTAL)
self.modulesView = Treeview(modulesFrame, xscrollcommand=hScrollbar.set, yscrollcommand=vScrollbar.set, height=7)
self.modulesView.grid(row=0, column=0, sticky=(N, S, E, W))
self.modulesView.bind('<<TreeviewSelect>>', self.moduleSelect)
hScrollbar["command"] = self.modulesView.xview
hScrollbar.grid(row=1, column=0, sticky=(E,W))
vScrollbar["command"] = self.modulesView.yview
vScrollbar.grid(row=0, column=1, sticky=(N,S))
modulesFrame.columnconfigure(0, weight=1)
modulesFrame.rowconfigure(0, weight=1)
modulesFrame.grid(row=0, column=1, columnspan=4, sticky=(N, S, E, W), padx=3, pady=3)
self.modulesView.focus_set()
self.modulesView.column("#0", width=120, anchor="w")
self.modulesView.heading("#0", text=_("Name"))
self.modulesView["columns"] = ("author", "ver", "status", "date", "update", "descr", "license")
self.modulesView.column("author", width=100, anchor="w", stretch=False)
self.modulesView.heading("author", text=_("Author"))
self.modulesView.column("ver", width=50, anchor="w", stretch=False)
self.modulesView.heading("ver", text=_("Version"))
self.modulesView.column("status", width=50, anchor="w", stretch=False)
self.modulesView.heading("status", text=_("Status"))
self.modulesView.column("date", width=70, anchor="w", stretch=False)
self.modulesView.heading("date", text=_("File Date"))
self.modulesView.column("update", width=50, anchor="w", stretch=False)
self.modulesView.heading("update", text=_("Update"))
self.modulesView.column("descr", width=200, anchor="w", stretch=False)
self.modulesView.heading("descr", text=_("Description"))
self.modulesView.column("license", width=70, anchor="w", stretch=False)
self.modulesView.heading("license", text=_("License"))
classesFrame = Frame(frame)
vScrollbar = Scrollbar(classesFrame, orient=VERTICAL)
hScrollbar = Scrollbar(classesFrame, orient=HORIZONTAL)
self.classesView = Treeview(classesFrame, xscrollcommand=hScrollbar.set, yscrollcommand=vScrollbar.set, height=5)
self.classesView.grid(row=0, column=0, sticky=(N, S, E, W))
hScrollbar["command"] = self.classesView.xview
hScrollbar.grid(row=1, column=0, sticky=(E,W))
vScrollbar["command"] = self.classesView.yview
vScrollbar.grid(row=0, column=1, sticky=(N,S))
classesFrame.columnconfigure(0, weight=1)
classesFrame.rowconfigure(0, weight=1)
classesFrame.grid(row=1, column=1, columnspan=4, sticky=(N, S, E, W), padx=3, pady=3)
self.classesView.focus_set()
self.classesView.column("#0", width=200, anchor="w")
self.classesView.heading("#0", text=_("Class"))
self.classesView["columns"] = ("modules",)
self.classesView.column("modules", width=500, anchor="w", stretch=False)
self.classesView.heading("modules", text=_("Modules"))
# bottom frame module info details
moduleInfoFrame = Frame(frame, width=700)
moduleInfoFrame.columnconfigure(1, weight=1)
self.moduleNameLabel = Label(moduleInfoFrame, wraplength=600, justify="left",
font=font.Font(family='Helvetica', size=12, weight='bold'))
self.moduleNameLabel.grid(row=0, column=0, columnspan=4, sticky=W)
self.moduleAuthorHdr = Label(moduleInfoFrame, text=_("author:"), state=DISABLED)
#.........这里部分代码省略.........
示例3: Download
# 需要导入模块: from tkinter.ttk import Label [as 别名]
# 或者: from tkinter.ttk.Label import config [as 别名]
class Download(Frame):
def __init__(self, master, **kwargs):
super(Download, self).__init__(master, borderwidth=20, **kwargs)
self.fs = None
self.tree = None
self.logfile = None
# User informations
self.info_tree = False
self.start_time = None
info = Frame(self, borderwidth=10)
self.info_label = Label(info, wraplength=350, borderwidth=20, justify='center', font=('a', 10, 'bold'))
self.info_indis = Label(info)
self.info_fams = Label(info)
self.info_sources = Label(info)
self.info_notes = Label(info)
self.time = Label(info)
self.info_label.grid(row=0, column=0, columnspan=2)
self.info_indis.grid(row=1, column=0)
self.info_fams.grid(row=1, column=1)
self.info_sources.grid(row=2, column=0)
self.info_notes.grid(row=2, column=1)
self.time.grid(row=3, column=0, columnspan=2)
self.form = Frame(self)
self.sign_in = SignIn(self.form)
self.options = None
self.title = Label(self, text=_('Sign In to FamilySearch'), font=('a', 12, 'bold'))
buttons = Frame(self)
self.btn_quit = Button(buttons, text=_('Quit'), command=Thread(target=self.quit).start)
self.btn_valid = Button(buttons, text=_('Sign In'), command=self.command_in_thread(self.login))
self.title.pack()
self.sign_in.pack()
self.form.pack()
self.btn_quit.pack(side='left', padx=(0, 40))
self.btn_valid.pack(side='right', padx=(40, 0))
info.pack()
buttons.pack(side='bottom')
self.pack()
self.update_needed = False
def info(self, text):
self.info_label.config(text=text)
def save(self):
filename = filedialog.asksaveasfilename(title=_('Save as'), defaultextension='.ged', filetypes=(('GEDCOM', '.ged'), (_('All files'), '*.*')))
if not filename:
return
with open(filename, 'w', encoding='utf-8') as file:
self.tree.print(file)
def login(self):
global _
username = self.sign_in.username.get()
password = self.sign_in.password.get()
if not (username and password):
messagebox.showinfo(message=_('Please enter your FamilySearch username and password.'))
return
self.btn_valid.config(state='disabled')
self.info(_('Login to FamilySearch...'))
self.logfile = open('download.log', 'w', encoding='utf-8')
self.fs = Session(self.sign_in.username.get(), self.sign_in.password.get(), verbose=True, logfile=self.logfile, timeout=1)
if not self.fs.logged:
messagebox.showinfo(_('Error'), message=_('The username or password was incorrect'))
self.btn_valid.config(state='normal')
self.info('')
return
self.tree = Tree(self.fs)
_ = self.fs._
self.title.config(text=_('Options'))
cache.delete('lang')
cache.add('lang', self.fs.lang)
self.options = Options(self.form, True)
self.info('')
self.sign_in.destroy()
self.options.pack()
self.master.change_lang()
self.btn_valid.config(command=self.command_in_thread(self.download), state='normal', text=_('Download'))
self.options.start_indis.add_indi(self.fs.get_userid())
self.update_needed = False
def quit(self):
self.update_needed = False
if self.logfile:
self.logfile.close()
super(Download, self).quit()
# prevent exception during download
os._exit(1)
def download(self):
todo = [self.options.start_indis.indis[key] for key in sorted(self.options.start_indis.indis)]
for fid in todo:
if not re.match(r'[A-Z0-9]{4}-[A-Z0-9]{3}', fid):
messagebox.showinfo(_('Error'), message=_('Invalid FamilySearch ID: ') + fid)
return
self.start_time = time.time()
self.options.destroy()
self.form.destroy()
self.title.config(text='FamilySearch to GEDCOM')
self.btn_valid.config(state='disabled')
#.........这里部分代码省略.........
示例4: DialogPluginManager
# 需要导入模块: from tkinter.ttk import Label [as 别名]
# 或者: from tkinter.ttk.Label import config [as 别名]
class DialogPluginManager(Toplevel):
def __init__(self, mainWin, modulesWithNewerFileDates):
super(DialogPluginManager, self).__init__(mainWin.parent)
self.ENABLE = _("Enable")
self.DISABLE = _("Disable")
self.parent = mainWin.parent
self.cntlr = mainWin
# copy plugins for temporary display
self.pluginConfig = PluginManager.pluginConfig
self.pluginConfigChanged = False
self.uiClassMethodsChanged = False
self.modulesWithNewerFileDates = modulesWithNewerFileDates
parentGeometry = re.match("(\d+)x(\d+)[+]?([-]?\d+)[+]?([-]?\d+)", self.parent.geometry())
dialogX = int(parentGeometry.group(3))
dialogY = int(parentGeometry.group(4))
self.title(_("Plug-in Manager"))
frame = Frame(self)
# left button frame
buttonFrame = Frame(frame, width=40)
buttonFrame.columnconfigure(0, weight=1)
addLabel = Label(buttonFrame, text=_("Find plug-in modules:"), wraplength=60, justify="center")
addLocalButton = Button(buttonFrame, text=_("Locally"), command=self.findLocally)
ToolTip(addLocalButton, text=_("File chooser allows selecting python module files to add (or reload) plug-ins, from the local file system."), wraplength=240)
addWebButton = Button(buttonFrame, text=_("On Web"), command=self.findOnWeb)
ToolTip(addWebButton, text=_("Dialog to enter URL full path to load (or reload) plug-ins, from the web or local file system."), wraplength=240)
addLabel.grid(row=0, column=0, pady=4)
addLocalButton.grid(row=1, column=0, pady=4)
addWebButton.grid(row=2, column=0, pady=4)
buttonFrame.grid(row=0, column=0, rowspan=2, sticky=(N, S, W), padx=3, pady=3)
# right tree frame (plugins already known to arelle)
modulesFrame = Frame(frame, width=700)
vScrollbar = Scrollbar(modulesFrame, orient=VERTICAL)
hScrollbar = Scrollbar(modulesFrame, orient=HORIZONTAL)
self.modulesView = Treeview(modulesFrame, xscrollcommand=hScrollbar.set, yscrollcommand=vScrollbar.set, height=7)
self.modulesView.grid(row=0, column=0, sticky=(N, S, E, W))
self.modulesView.bind('<<TreeviewSelect>>', self.moduleSelect)
hScrollbar["command"] = self.modulesView.xview
hScrollbar.grid(row=1, column=0, sticky=(E,W))
vScrollbar["command"] = self.modulesView.yview
vScrollbar.grid(row=0, column=1, sticky=(N,S))
modulesFrame.columnconfigure(0, weight=1)
modulesFrame.rowconfigure(0, weight=1)
modulesFrame.grid(row=0, column=1, columnspan=4, sticky=(N, S, E, W), padx=3, pady=3)
self.modulesView.focus_set()
self.modulesView.column("#0", width=120, anchor="w")
self.modulesView.heading("#0", text=_("Name"))
self.modulesView["columns"] = ("author", "ver", "status", "date", "update", "descr", "license")
self.modulesView.column("author", width=100, anchor="w", stretch=False)
self.modulesView.heading("author", text=_("Author"))
self.modulesView.column("ver", width=50, anchor="w", stretch=False)
self.modulesView.heading("ver", text=_("Version"))
self.modulesView.column("status", width=50, anchor="w", stretch=False)
self.modulesView.heading("status", text=_("Status"))
self.modulesView.column("date", width=70, anchor="w", stretch=False)
self.modulesView.heading("date", text=_("File Date"))
self.modulesView.column("update", width=50, anchor="w", stretch=False)
self.modulesView.heading("update", text=_("Update"))
self.modulesView.column("descr", width=200, anchor="w", stretch=False)
self.modulesView.heading("descr", text=_("Description"))
self.modulesView.column("license", width=70, anchor="w", stretch=False)
self.modulesView.heading("license", text=_("License"))
classesFrame = Frame(frame)
vScrollbar = Scrollbar(classesFrame, orient=VERTICAL)
hScrollbar = Scrollbar(classesFrame, orient=HORIZONTAL)
self.classesView = Treeview(classesFrame, xscrollcommand=hScrollbar.set, yscrollcommand=vScrollbar.set, height=5)
self.classesView.grid(row=0, column=0, sticky=(N, S, E, W))
hScrollbar["command"] = self.classesView.xview
hScrollbar.grid(row=1, column=0, sticky=(E,W))
vScrollbar["command"] = self.classesView.yview
vScrollbar.grid(row=0, column=1, sticky=(N,S))
classesFrame.columnconfigure(0, weight=1)
classesFrame.rowconfigure(0, weight=1)
classesFrame.grid(row=1, column=1, columnspan=4, sticky=(N, S, E, W), padx=3, pady=3)
self.classesView.focus_set()
self.classesView.column("#0", width=200, anchor="w")
self.classesView.heading("#0", text=_("Class"))
self.classesView["columns"] = ("modules")
self.classesView.column("modules", width=500, anchor="w", stretch=False)
self.classesView.heading("modules", text=_("Modules"))
# bottom frame module info details
moduleInfoFrame = Frame(frame, width=700)
moduleInfoFrame.columnconfigure(1, weight=1)
self.moduleNameLabel = Label(moduleInfoFrame, wraplength=600, justify="left",
font=font.Font(family='Helvetica', size=12, weight='bold'))
self.moduleNameLabel.grid(row=0, column=0, columnspan=4, sticky=W)
self.moduleAuthorHdr = Label(moduleInfoFrame, text=_("author:"), state=DISABLED)
self.moduleAuthorHdr.grid(row=1, column=0, sticky=W)
self.moduleAuthorLabel = Label(moduleInfoFrame, wraplength=600, justify="left")
self.moduleAuthorLabel.grid(row=1, column=1, columnspan=3, sticky=W)
#.........这里部分代码省略.........
示例5: Application
# 需要导入模块: from tkinter.ttk import Label [as 别名]
# 或者: from tkinter.ttk.Label import config [as 别名]
class Application(Frame):
"""The main Tk application, a simple dialog."""
def __init__(self, master=None):
super().__init__(master)
self.badge = None
self.grid()
self.columnconfigure(0, minsize=200)
self.columnconfigure(1, minsize=200)
self.rowconfigure(0, minsize=300)
self.rowconfigure(3, minsize=30)
self.create_widgets()
self.connect()
def create_widgets(self):
"""Sets up dialog elements."""
self.select = tix.FileSelectBox(self, browsecmd=self.on_file_selected,
pattern="*.fs", directory="forth")
# self.select["textVariable"] = self.forth_file
self.select.grid(row=0, columnspan=2, sticky='n'+'w'+'e')
self.connect_btn = Button(self, text="Connect",
command=self.toggle_connect)
self.connect_btn.grid(row=1, column=0, columnspan=2)
self.exec_btn = Button(self, text="Execute", command=self.send_file)
self.exec_btn.state(["disabled"])
self.exec_btn.grid(row=2, column=0, sticky='w' + 'e', padx=5, pady=3)
self.quit = Button(self, text="QUIT", command=self.master.destroy)
self.quit.grid(row=2, column=1, sticky='w' + 'e', padx=5, pady=3)
self.status_panel = Frame(self, relief="groove", borderwidth=3)
self.status_panel.grid(row=3, columnspan=2, sticky='nwse')
self.connect_status = Label(self.status_panel, text="Not Connected")
self.connect_status.grid(row=0, padx=5, pady=5, sticky="w")
if self.badge is not None:
self.connect_btn.state(["disabled"])
self.connect_status.config(text="Connected: " + self.badge.os_device)
def send_file(self, _retry=False):
"""Send the selected file to the badge."""
if self.badge:
try:
# oddly, very first set LED seems to not set correct color
self.badge.led(0, 0, 128)
self.badge.led(0, 0, 128)
with open(self.select.cget("value"), 'r') as forthin:
self.badge.forth_run(forthin.read())
time.sleep(1) # because forth_run() may be too fast
self.badge.led(0, 128, 0)
except IOError:
if not _retry:
self.connect()
self.send_file(True)
else:
raise
def toggle_connect(self):
"If connected, disconnect, otherwise connect."
if self.connect_btn.cget("text") == "Connect":
self.connect()
else:
self.disconnect()
def disconnect(self):
"Disconnect from current badge."
isinstance(self.badge, Badge)
self.badge.close()
self.badge = None
self.connect_btn.config(text="Connect")
self.connect_status.config(text="Not connected.")
self.exec_btn.state(["disabled"])
def connect(self):
"""Attempt to connect to a badge; toggle Connect button if successful."""
try:
self.badge = Badge()
self.connect_status.config(text="Connected: " + self.badge.os_device)
self.connect_btn.config(text="Disconnect")
# enable "Execute" if file is selected
self.on_file_selected(self.select.cget("value"))
except BadgeSerialException:
self.connect_status.config(text="Not connected")
def on_file_selected(self, selected_file):
"""Respond to user selection of file by enabling the Execute button."""
if Path(selected_file).is_file:
self.exec_btn.state(["!disabled"])
else:
self.exec_btn.state(["disabled"])
示例6: SolutionTabFrame
# 需要导入模块: from tkinter.ttk import Label [as 别名]
# 或者: from tkinter.ttk.Label import config [as 别名]
class SolutionTabFrame(Frame):
''' This class is responsible for displaying solution on the screen.
It extends Frame class.
Attributes:
parent (Tk object that can contain Frame): parent that can
contain Frame, MUST implement method
change_solution_tab_name(str).
data_from_file_lbl (Label): label that contains file name
with data if specified.
solution_tab (SolutionFrameWithText): notebook with tabs
describing solution.
model_solutions (list of Solution): list with one or more
solutions that have been generated after running algorithm.
param_strs (list of str): list with strings that should appear
before printing every solution from model_solutions.
ranks (list of list of int): list of ranks corresponding to
every solution from model_solutions, ranks are generated
by peel-the-onion algorithm.
categorical (str): name of the categorical variable used in
categorical analysis.
progress_bar (Progressbar): progress bar to show how solution
is loaded or saved to file.
status_lbl (Label): label for displaying solution status.
solution_format_var (IntVar): IntVar object that tracks which
file format is chosen for solution.
'''
def __init__(self, parent, *args, **kw):
super().__init__(parent, *args, **kw)
self.parent = parent
self.data_from_file_lbl = None
self.solution_tab = None
self.model_solutions = None
self.param_strs = None
self.ranks = None
self.params = None
self.categorical = None
self.run_date = None
self.total_seconds = 0
self.progress_bar = None
self.status_lbl = None
self.solution_format_var = IntVar()
self.create_widgets()
def create_widgets(self):
''' Creates appropriate widgets on this frame.
'''
self.columnconfigure(0, weight=1)
self.rowconfigure(3, weight=1)
frame_for_save_btn = Frame(self)
frame_for_save_btn.columnconfigure(1, weight=1)
self.status_lbl = Label(frame_for_save_btn, text='')
self.status_lbl.grid(row=0, column=1, sticky=N+W)
save_solution_btn = Button(frame_for_save_btn, text='Save solution',
command=self.on_save_solution)
save_solution_btn.grid(row=1, column=0, sticky=W+N, padx=5, pady=5)
self.progress_bar = Progressbar(frame_for_save_btn,
mode='determinate', maximum=100)
self.progress_bar.grid(row=1, column=1, sticky=W+E, padx=10, pady=5)
frame_for_save_btn.grid(sticky=W+N+E+S, padx=5, pady=5)
frame_for_btns = Frame(self)
self._create_file_format_btn('*.xlsx', 1, frame_for_btns, 0)
self._create_file_format_btn('*.xls', 2, frame_for_btns, 1)
self._create_file_format_btn('*.csv', 3, frame_for_btns, 2)
self.solution_format_var.set(1)
frame_for_btns.grid(row=1, column=0, sticky=W+N+E+S, padx=5, pady=5)
self.data_from_file_lbl = Label(self, text=TEXT_FOR_FILE_LBL, anchor=W,
justify=LEFT,
wraplength=MAX_FILE_PARAMS_LBL_LENGTH)
self.data_from_file_lbl.grid(row=2, column=0, padx=5, pady=5,
sticky=W+N)
self.solution_tab = SolutionFrameWithText(self)
self.solution_tab.grid(row=3, column=0, sticky=W+E+S+N, padx=5, pady=5)
def _create_file_format_btn(self, btn_text, var_value, parent, column):
''' Creates and grids Radiobutton used for choosing solution file
format.
Args:
btn_text (str): text displayed next to the Radiobutton.
var_value (int): value of the IntVar associated with this
Radiobutton.
parent (Tk object): parent of this Radiobutton.
column (int): column index where this Radiobutton
should be gridded.
'''
sol_format_btn = Radiobutton(parent, text=btn_text,
variable=self.solution_format_var,
value=var_value)
sol_format_btn.grid(row=2, column=column, sticky=W+N, padx=2)
def on_save_solution(self):
''' Saves solution to file.
This method is called when save solution button is pressed.
If there is a solution, this method will ask user to provide
#.........这里部分代码省略.........
示例7: Example
# 需要导入模块: from tkinter.ttk import Label [as 别名]
# 或者: from tkinter.ttk.Label import config [as 别名]
class Example(Frame):
def __init__(self, parent):
Frame.__init__(self, parent)
self.parent = parent
self.initUI()
def initUI(self):
self.parent.title("")
self.style = Style()
self.style.theme_use("clam")
self.pack(fill=BOTH, expand = 1)
self.labelU = Label(self, text="U:")
self.labelP = Label(self, text="P:")
self.entryUsername = Entry(self)
self.entryUsername.config(relief='flat')
self.entryUsername.focus_set()
self.entryUsername.bind('<Return>', lambda event: self.entryPassword.focus_set())
self.entryPassword = Entry(self)
self.entryPassword.config(relief='flat', show='•')
self.entryPassword.bind('<Return>', lambda event: self.login(self.entryUsername.get(), self.entryPassword.get()))
self.newbutton = Button(self, text="Login", command= lambda: self.login(self.entryUsername.get(), self.entryPassword.get()))
self.newbutton.bind('<Return>', lambda event: self.login(self.entryUsername.get(), self.entryPassword.get()))
self.newbutton.config(width=6)
self.quitbutton = Button(self, text="Quit", command= lambda: self.quit())
self.quitbutton.config(width=6)
self.mailIconRed = PhotoImage(file="mail.gif")
self.labelRed = Label(self, image=self.mailIconRed)
self.mailIconGray = PhotoImage(file="mail2.gif")
self.labelGray = Label(self, image=self.mailIconGray)
self.labelKarma = Label(self, text = '•')
self.labelU.grid(row=0, column=0)
self.entryUsername.grid(row=0, column=1)
self.labelP.grid(row=1, column=0)
self.entryPassword.grid(row=1, column=1, pady=4)
self.newbutton.grid(row=2, column=1)
self.quitbutton.grid(row=3, column=1, pady=4)
'''
sw = self.parent.winfo_screenwidth()
sh = self.parent.winfo_screenheight()
w=150
h=112
x = (sw - w) / 2
y = (sh - h) / 2
self.parent.geometry('%dx%d+%d+%d' % (w, h, x, y-50))
'''
def login(self, username, password):
#print('U: ' + username)
self.username = username
if username == '':
#print('Please enter a username')
self.entryUsername.focus_set()
elif password == '':
#print('Please enter a password')
self.entryPassword.set_focus()
if username != '' and password != '':
#print('Attempting login for ' + username)
try:
self.USERAGENT = username + ' scans his inbox for new mail.'
self.r = praw.Reddit(self.USERAGENT)
#self.r.config._ssl_url = None
self.r.login(username, password)
#print('You have logged in as ' + username)
self.labelU.grid_forget()
self.labelP.grid_forget()
self.entryUsername.grid_forget()
self.entryPassword.grid_forget()
self.newbutton.grid_forget()
self.quitbutton.grid_forget()
self.usernamelabel = Label(self, text=username)
self.usernamelabel.grid(row=0, column=0, pady = 10, padx = 30)
self.quitbutton.grid(row=1, column=0)
self.labelKarma.grid(row = 3, column = 0)
self.playedSound = 'false'
self.loop()
except praw.errors.InvalidUserPass:
pass
#print('Invalid username or password')
def loop(self):
while True:
try:
#print('Starting new search')
hasmail = 'false'
for msg in self.r.get_unread(limit=None):
hasmail = 'true'
#.........这里部分代码省略.........
示例8: Example
# 需要导入模块: from tkinter.ttk import Label [as 别名]
# 或者: from tkinter.ttk.Label import config [as 别名]
class Example(Frame):
def __init__(self, parent):
Frame.__init__(self, parent)
self.parent = parent
self.initUI()
def initUI(self):
self.username = ''
self.r = praw.Reddit(USERAGENT)
self.parent.title("")
self.style = Style()
self.style.theme_use("clam")
self.pack(fill=BOTH, expand = 1)
self.labelU = Label(self, text="U:")
self.labelP = Label(self, text="P:")
self.entryUsername = Entry(self)
self.entryUsername.config(relief='flat')
self.entryUsername.focus_set()
self.entryUsername.bind('<Return>', lambda event: self.login(self.entryUsername.get()))
self.entryUsername.bind('<Up>', lambda event: self.entryUsername.insert(0, self.username))
self.quitbutton = Button(self, text="Quit", command= lambda: self.quit())
self.quitbutton.config(width=6)
self.labelKarma = Label(self, text = '•')
self.labelKarma.grid(row = 3, column = 1)
self.labelU.grid(row=0, column=0)
self.entryUsername.grid(row=0, column=1)
self.quitbutton.grid(row=2, column=1, pady=4)
self.usernamelabel = Label(self, text='')
self.usernamelabel.grid(row=1, column=1)
def login(self, username):
print('U: ' + username)
self.username = username
self.entryUsername.delete(0, 200)
if username == '':
self.entryUsername.focus_set()
else:
try:
self.user = self.r.get_redditor(self.username)
lkarma = str(self.user.link_karma)
ckarma = str(self.user.comment_karma)
lkarma = self.karmaRound(lkarma)
ckarma = self.karmaRound(ckarma)
karmastring = lkarma + ' • ' + ckarma
self.labelKarma.config(text = karmastring)
self.usernamelabel.config(text= self.username)
except:
self.labelKarma.config(text = '•')
self.usernamelabel.config(text= 'User not found')
pass
def karmaRound(self, karma):
if len(karma) > 4 and len(karma) < 7:
tstring = karma[:-3]
tstring2 = karma[-3:]
karma = tstring + '.' + tstring2[:2] + 'K'
return karma
if len(karma) > 6:
tstring = karma[:-6]
tstring2 = karma[-6:]
karma = tstring + '.' + tstring2[:2] + 'M'
return karma
else:
return karma
示例9: MainFrame
# 需要导入模块: from tkinter.ttk import Label [as 别名]
# 或者: from tkinter.ttk.Label import config [as 别名]
class MainFrame(Frame):
''' This class implements main GUI of the application.
Attributes:
parent (Tk object): parent of this frame (Tk()).
params_frame (ParamsFrame): frame with parameters.
data_frame (DataFrame): frame with data and solution.
progress_bar (Progressbar): progress bar widget.
increment (int): progress bar increment, it is modified
in other classes that are responsible for solving
the problem and update progress.
weights_status_lbl (Label): label that displays if weight
restrictions are feasible.
weights_status_str (StringVar): StringVar object used for
tracking if weight restrictions are feasible.
current_categories (list of str): list of current categories.
Args:
parent (Tk object): parent of this frame (Tk()).
'''
def __init__(self, parent, *args, **kwargs):
Frame.__init__(self, parent, *args, **kwargs)
self.parent = parent
self.params_frame = None
self.data_frame = None
self.progress_bar = None
self.increment = 0
self.weights_status_lbl = None
self.weights_status_str = StringVar()
self.weights_status_str.trace('w', self.on_weights_status_change)
self.current_categories = []
self.create_widgets()
def create_widgets(self):
''' Creates all widgets that belong to this frame.
'''
self.parent.title('pyDEA')
self.pack(fill=BOTH, expand=1)
self.columnconfigure(0, weight=1, pad=5)
self.columnconfigure(1, weight=0, pad=5)
self.rowconfigure(0, pad=3, weight=1)
self.rowconfigure(1, pad=3)
self.rowconfigure(2, pad=3)
self.rowconfigure(3, pad=3)
self.current_categories = []
data_from_params_file = StringVar()
str_var_for_input_output_boxes = ObserverStringVar()
self.params_frame = ParamsFrame(self, self.current_categories,
data_from_params_file,
str_var_for_input_output_boxes,
self.weights_status_str)
data_frame = DataFrame(self, self.params_frame, self.current_categories,
data_from_params_file,
str_var_for_input_output_boxes)
self.data_frame = data_frame
data_frame.grid(row=0, column=0, sticky=N+S+W+E, padx=15, pady=15)
self.params_frame.grid(row=0, column=1, sticky=W+E+S+N, padx=15,
pady=15, columnspan=2)
lbl_progress = Label(self, text='Progress')
lbl_progress.grid(row=1, column=0, sticky=W, padx=10, pady=5)
self.progress_bar = Progressbar(self, mode='determinate', maximum=100)
self.progress_bar.grid(row=2, column=0, sticky=W+E, padx=10, pady=5)
run_btn = Button(self, text='Run', command=self.run)
run_btn.grid(row=2, column=1, sticky=W, padx=10, pady=10)
self.weights_status_lbl = Label(self, text='', foreground='red')
self.weights_status_lbl.grid(row=2, column=2, padx=10, pady=5, sticky=W)
def on_weights_status_change(self, *args):
''' This method is called when weight restrictions status is changed.
'''
self.weights_status_lbl.config(text=self.weights_status_str.get())
def run(self):
''' This method is called when the user presses Run button.
Solves the problem and displays solution.
'''
clean_up_pickled_files()
params = self.params_frame.params
run_method = RunMethodGUI(self)
run_method.run(params)
def construct_categories(self):
''' Returns current categories.
Returns:
(list of str): list of current categories
'''
return [category.strip() for category in self.current_categories
if category]
def on_dmu_change(self, *args):
''' Updates progress bar.
'''
#.........这里部分代码省略.........