本文整理汇总了Python中tkinter.Label.cget方法的典型用法代码示例。如果您正苦于以下问题:Python Label.cget方法的具体用法?Python Label.cget怎么用?Python Label.cget使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tkinter.Label
的用法示例。
在下文中一共展示了Label.cget方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Image_
# 需要导入模块: from tkinter import Label [as 别名]
# 或者: from tkinter.Label import cget [as 别名]
class Image_(Widget_):
def __init__(self, parent_frame, x, y):
Widget_.__init__(self, parent_frame, x, y)
self.label = Label(self.widget_frame)
self.label.pack()
self.label_bg, self.label_fg = None, None
#def get_(self):
# return self.picture
def get_info(self):
return self.label.cget('text')
def settings(self, **kwargs):
''' all setting changes '''
if 'label_bg' in kwargs:
self.label.config(bg=kwargs['label_bg'])
if 'label_fg' in kwargs:
self.label.config(fg=kwargs['label_fg'])
if 'image' in kwargs:
self.img_path = kwargs['image']
self.picture = Image.open(self.img_path)
self.image = ImageTk.PhotoImage(self.picture)
self.label.config(image=self.image)
if 'resize' in kwargs:
self.picture = self.picture.resize(kwargs['resize'], Image.ANTIALIAS)
self.image = ImageTk.PhotoImage(self.picture)
self.label.config(image=self.image)
return
示例2: _Tk_Nosy
# 需要导入模块: from tkinter import Label [as 别名]
# 或者: from tkinter.Label import cget [as 别名]
class _Tk_Nosy(object):
"""This class is the tkinter GUI object"""
def __init__(self, master):
self.dirname = os.path.abspath( os.curdir )
self.initComplete = 0
self.master = master
self.x, self.y, self.w, self.h = -1,-1,-1,-1
# bind master to <Configure> in order to handle any resizing, etc.
# postpone self.master.bind("<Configure>", self.Master_Configure)
self.master.bind('<Enter>', self.bindConfigure)
self.menuBar = Menu(master, relief = "raised", bd=2)
top_Directory = Menu(self.menuBar, tearoff=0)
top_Directory.add("command", label = "Change Dir", command = self.menu_Directory_Change_Dir)
self.menuBar.add("cascade", label="Directory", menu=top_Directory)
#top_Snippet = Menu(self.menuBar, tearoff=0)
self.menuBar.add("command", label = "Run", command = self.menu_Run)
master.config(menu=self.menuBar)
# make a Status Bar
self.statusMessage = StringVar()
self.statusMessage.set(self.dirname)
self.statusbar = Label(self.master, textvariable=self.statusMessage, bd=1, relief=SUNKEN)
self.statusbar.pack(anchor=SW, fill=X, side=BOTTOM)
self.statusbar_bg = self.statusbar.cget('bg') # save bg for restore
myFont = tkinter.font.Font(family="Arial", size=12, weight=tkinter.font.BOLD)
self.statusbar.config( font=myFont )
frame = Frame(master)
frame.pack(anchor=NE, fill=BOTH, side=TOP)
self.Pass_Fail_Button = Button(frame,text="Pass/Fail Will Be Shown Here",
image="", width="15", background="green",
anchor=W, justify=LEFT, padx=2)
self.Pass_Fail_Button.pack(anchor=NE, fill=X, side=TOP)
self.Pass_Fail_Button.bind("<ButtonRelease-1>", self.Pass_Fail_Button_Click)
#self.master.title("tk_nosy")
self.master.title('Python %s.%s.%s '%sys.version_info[:3])
self.oscillator = 1 # animates character on title
self.oscillator_B = 0 # used to return statusbar to statusbar_bg
self.lbframe = Frame( frame )
self.lbframe.pack(anchor=SE, side=LEFT, fill=BOTH, expand=1)
scrollbar = Scrollbar(self.lbframe, orient=VERTICAL)
self.Text_1 = Text(self.lbframe, width="80", height="24", yscrollcommand=scrollbar.set)
scrollbar.config(command=self.Text_1.yview)
scrollbar.pack(side=RIGHT, fill=Y)
self.Text_1.pack(side=LEFT, fill=BOTH, expand=1)
self.master.resizable(1,1) # Linux may not respect this
self.numNosyCalls = 0
self.need_to_pick_dir = 1
if len(sys.argv)>1:
# I don't care what the exception is, if there's a problem, bail
# pylint: disable=W0702
try:
dirname = os.path.abspath( sys.argv[1] )
self.try_change_to_new_dir( dirname )
except:
pass # let Alarm force dir selection
else:
try:
if os.path.isdir(os.path.join( self.dirname, 'tests' )):
self.try_change_to_new_dir( self.dirname )
except:
pass # let Alarm force dir selection
print(LICENSE)
self.Alarm()
def try_change_to_new_dir(self, dirname):
"""A legal abspath will switch to dirname."""
# I don't care what the exception is, if there's a problem, bail
# pylint: disable=W0702
if dirname:
try:
dirname = os.path.abspath( dirname )
except:
return # let Alarm force dir selection
else:
return
self.dirname = dirname
#.........这里部分代码省略.........
示例3: Textbox
# 需要导入模块: from tkinter import Label [as 别名]
# 或者: from tkinter.Label import cget [as 别名]
class Textbox(Widget_):
def __init__(self, parent_frame, x, y):
Widget_.__init__(self, parent_frame, x, y)
self.label_width = 15
self.entry_width = 20
self.stringvar = StringVar()
self.label = Label(self.widget_frame, width=self.label_width, anchor=E)
self.entry = Entry(self.widget_frame, width=self.entry_width, textvariable=self.stringvar, relief=FLAT)
self.label.pack(side=LEFT, padx=3)
self.entry.pack(side=LEFT)
self.label_bg, self.label_fg, self.label_hover_bg, self.label_hover_fg = None, None, None, None
self.entry_bg, self.entry_fg, self.entry_focus_bg, self.entry_focus_fg = '#FFFFFF', None, '#D0F2ED', None
self.widget_frame.bind('<FocusIn>', lambda event: self.entry.config(bg=self.entry_focus_bg))
self.widget_frame.bind('<FocusOut>', lambda event: self.entry.config(bg=self.entry_bg))
#def get_(self):
# return self.entry.get()
def get_info(self):
return self.label.cget('text'), self.entry.get()
def settings(self, **kwargs):
if 'label' in kwargs:
self.label.config(text=kwargs['label'])
if 'entry_state' in kwargs:
self.entry_state = kwargs['entry_state']
self.entry.config(state=self.entry_state)
if 'entry' in kwargs:
if hasattr(self, 'entry_state') and self.entry_state == DISABLED:
self.entry.config(state=NORMAL)
self.stringvar.set(kwargs['entry'])
if hasattr(self, 'entry_state') and self.entry_state == DISABLED:
self.entry.config(state=DISABLED)
if 'label_bg' in kwargs:
self.label_bg = kwargs['label_bg']
self.label.config(bg=self.label_bg)
if 'label_fg' in kwargs:
self.label_fg = kwargs['label_fg']
self.label.config(fg=self.label_fg)
def set_input_restriction(self, string):
def OnValidate(d, i, P, s, S, v, V, W, string):
if d == 0:
return True
accepted_inputs = string.split(',')
if 'int' in accepted_inputs and S.isdigit():
return True
if 'lower' in accepted_inputs:
S = S.lower()
return True
if 'upper' in accepted_inputs:
S = S.upper()
return True
return False
self.vcmd = self.widget_frame.register(OnValidate), '%d', '%i', '%P', '%s', '%S', '%v', '%V', '%W', string
self.entry.config(validate="all", validatecommand=self.vcmd)
return
pass
示例4: Button_
# 需要导入模块: from tkinter import Label [as 别名]
# 或者: from tkinter.Label import cget [as 别名]
class Button_(Widget_):
def __init__(self, parent_frame, x, y):
Widget_.__init__(self, parent_frame, x, y)
self.label_bg, self.label_fg = 'grey', 'white'
self.hover_bg, self.hover_fg = None, None
self.label = Label(self.widget_frame, bg=self.label_bg, fg=self.label_fg)
self.label.grid(row=0, column=1, ipadx=5, ipady=10)
def get_info(self):
return self.label.cget('text')
def set_hover(self):
def set_hover_bg(event):
self.label.config(bg=self.hover_bg, fg=self.hover_fg)
self.img.config(bg=self.hover_bg, fg=self.hover_fg)
def remove_hover_bg(event):
self.label.config(bg=self.label_bg, fg=self.label_fg)
self.img.config(bg=self.label_bg, fg=self.label_fg)
if hasattr(self, 'img'):
self.widget_frame.bind('<Enter>', set_hover_bg)
self.widget_frame.bind('<Leave>', remove_hover_bg)
else:
self.widget_frame.bind('<Enter>', lambda event: self.label.config(bg=self.hover_bg, fg=self.hover_fg))
self.widget_frame.bind('<Leave>', lambda event: self.label.config(bg=self.label_bg, fg=self.label_fg))
def settings(self, **kwargs):
''' all setting changes '''
if 'label_bg' in kwargs:
self.label_bg = kwargs['label_bg']
self.label.config(bg=self.label_bg)
if 'label_fg' in kwargs:
self.label_fg = kwargs['label_fg']
self.label.config(fg=self.label_fg)
if 'text' in kwargs:
self.label.config(text=kwargs['text'])
if 'font' in kwargs:
self.label.config(font=kwargs['font'])
if 'hover_bg' in kwargs:
self.hover_bg = kwargs['hover_bg']
self.hover_fg = self.label_fg if self.hover_fg == None else self.hover_fg
self.set_hover()
if 'hover_fg' in kwargs:
self.hover_fg = kwargs['hover_fg']
self.hover_bg = self.label_bg if self.hover_bg == None else self.hover_bg
self.set_hover()
if 'command' in kwargs:
self.command = kwargs['command']
self.label.bind('<Button-1>', lambda event: self.command())
if hasattr(self, 'img'):
self.img.bind('<Button-1>', lambda event: self.command())
if 'image' in kwargs:
self.img_path = kwargs['image']
self.picture = Image.open(self.img_path)
self.image = ImageTk.PhotoImage(self.picture)
self.img = Label(self.widget_frame, bg=self.label_bg, fg=self.label_fg)
self.img.grid(row=0, column=0, ipadx=5, ipady=5, columnspan=2, sticky=W)
self.img.config(image=self.image)
self.set_hover()
if hasattr(self, 'command'):
self.img.bind('<Button-1>', lambda event: self.command())
if 'image_resize' in kwargs:
self.picture = self.picture.resize(kwargs['image_resize'], Image.ANTIALIAS)
self.image = ImageTk.PhotoImage(self.picture)
self.img.config(image=self.image)
return
示例5: SatelliteWindow
# 需要导入模块: from tkinter import Label [as 别名]
# 或者: from tkinter.Label import cget [as 别名]
class SatelliteWindow( Toplevel ):
"""
SatelliteWindow is used to display nosetests results of concurrently run
python interpreters.
"""
def cleanupOnQuit(self):
"""When closing popup, do a little clean up."""
# I'm not sure that transient windows need this, but I'm trying to be careful
self.MainWin.focus_set()
if self.main_gui.kill_popup_window( self.statusMessage.get() ):
self.destroy()
self.main_gui.statusMessage.set('Closed: ' + self.statusMessage.get())
else:
self.main_gui.statusMessage.set('ERROR Closing: ' + self.statusMessage.get())
self.main_gui.set_statusbar_bg( '#FF9999' )
def __init__(self, main_gui, MainWin, mytitle, dx=30, dy=30):
"""Initialize popup"""
Toplevel.__init__(self, MainWin)
self.title(mytitle)
x = MainWin.winfo_x()
if x<10:
x=10
y = MainWin.winfo_y()
if y<10:
y=10
# position over to the upper right
self.geometry( '+%i+%i'%(x+dx,y+dy))
self.config( highlightcolor='#FF99FF', highlightbackground='#FF99FF',
highlightthickness=2, borderwidth=10 )
#===========
# make a Status Bar
self.statusMessage = StringVar()
self.statusMessage.set(mytitle)
self.statusbar = Label(self, textvariable=self.statusMessage, bd=1, relief=SUNKEN)
self.statusbar.pack(anchor=SW, fill=X, side=BOTTOM)
self.statusbar_bg = self.statusbar.cget('bg') # save bg for restore
myFont = tkinter.font.Font(family="Arial", size=12, weight=tkinter.font.BOLD)
self.statusbar.config( font=myFont )
frame = Frame(self)
frame.pack(anchor=NE, fill=BOTH, side=TOP)
self.Pass_Fail_Button = Button(frame,text="Pass/Fail Will Be Shown Here",
image="", width="15", background="green",
anchor=W, justify=LEFT, padx=2)
self.Pass_Fail_Button.pack(anchor=NE, fill=X, side=TOP)
self.Pass_Fail_Button.bind("<ButtonRelease-1>", self.Pass_Fail_Button_Click)
#self.title('%s %s.%s.%s '%(python_exe_name, python_major, python_minor, python_micro))
self.oscillator = 1 # animates character on title
self.oscillator_B = 0 # used to return statusbar to statusbar_bg
self.lbframe = Frame( frame )
self.lbframe.pack(anchor=SE, side=LEFT, fill=BOTH, expand=1)
scrollbar = Scrollbar(self.lbframe, orient=VERTICAL)
self.Text_1 = Text(self.lbframe, width="80", height="24", yscrollcommand=scrollbar.set)
scrollbar.config(command=self.Text_1.yview)
scrollbar.pack(side=RIGHT, fill=Y)
self.Text_1.pack(side=LEFT, fill=BOTH, expand=1)
self.resizable(1,1) # Linux may not respect this
#===========
self.MainWin = MainWin
self.main_gui = main_gui
# only main window can close this window
self.protocol('WM_DELETE_WINDOW', self.cleanupOnQuit)
def Pass_Fail_Button_Click(self, event):
"""Place-holder routine for user clicking Pass/Fail Button"""
self.main_gui.Pass_Fail_Button_Click( event )
def reset_statusbar_bg(self):
"""Return status bar to default state"""
self.statusbar.config(bg=self.statusbar_bg)
def set_statusbar_bg(self, c):
"""Set status bar to show new color and message"""
self.statusbar.config(bg=c)
self.oscillator_B = 1 # will return to initial color after a few cycles
示例6: __init__
# 需要导入模块: from tkinter import Label [as 别名]
# 或者: from tkinter.Label import cget [as 别名]
class MultipleRunGUI:
"""GUI for batch and SxS modes for displaying the stats."""
def __init__(self, *, multiple_runner_class, input_spec, left_name,
right_name):
"""Sets up windows and the instance of RunMultipleTimes that will do the actual work."""
#: The input_spec is an iterable of
#: :py:class:`farg.core.read_input_spec.SpecificationForOneRun`.
self.input_spec = input_spec
#: Class responsible for the actual running multiple times.
self.multiple_runner_class = multiple_runner_class
#: Main window
self.mw = mw = Tk()
#: Statistics thus far, grouped by input.
self.stats = AllStats(left_name=left_name, right_name=right_name)
#: Are we in the process of quitting?
self.quitting = False
self.status_label = Label(
mw, text='Not Started', font=('Times', 20), foreground='#000000')
self.status_label_text = self.status_label.cget('text')
self.status_label.pack(side=TOP, expand=True, fill=X)
#: Has a run started? Used to ensure single run.
self.run_started = False
details_frame = Frame(mw)
details_frame.pack(side=TOP)
#: listbox on left listing inputs.
frame = Frame(details_frame)
scrollbar = Scrollbar(frame, orient=VERTICAL)
listbox = Listbox(
frame,
yscrollcommand=scrollbar.set,
height=25,
width=70,
selectmode=SINGLE)
scrollbar.config(command=listbox.yview)
scrollbar.pack(side=RIGHT, fill=Y)
listbox.pack(side=LEFT, fill=BOTH, expand=1)
listbox.bind('<ButtonRelease-1>', self.SelectForDisplay, '+')
frame.pack(side=LEFT)
self.listbox = listbox
#: Canvas on right for details
self.canvas = Canvas(
details_frame,
width=kCanvasWidth,
height=kCanvasHeight,
background='#FFFFFF')
self.canvas.pack(side=LEFT)
#: which input are we displaying the details of?
self.display_details_for = None
#: Thread used for running
self.thread = None
self.mw.bind('<KeyPress-q>', lambda e: self.Quit())
self.mw.bind('<KeyPress-r>', lambda e: self.KickOffRun())
self.Refresher()
self.mw.after(1000, self.KickOffRun)
def SelectForDisplay(self, _event):
"""Event-handler called when an input was selected for detailed display."""
selected = self.listbox.curselection()
if not selected:
selected = ['0']
self.display_details_for = self.listbox.get(selected[0])
def Quit(self):
"""Called when the user has indicated that the application should Quit.
Waits for any ongoing run to finish, and then destroys windows.
"""
self.quitting = True
if self.thread:
self.thread.join()
self.mw.quit()
def Refresher(self):
"""Repeatedly refreshes the display."""
self.UpdateDisplay()
self.mw.after(100, self.Refresher)
def KickOffRun(self):
"""Start run if it has not already started."""
if self.run_started:
return
self.run_started = True
self.thread = self.multiple_runner_class(
input_spec=self.input_spec, gui=self)
self.thread.start()
def UpdateDisplay(self):
"""Displays the Stats."""
current_selection = self.listbox.curselection()
self.listbox.delete(0, END)
self.canvas.delete('all')
inputs = self.stats.input_order
self.status_label.configure(text=self.status_label_text)
if not inputs:
#.........这里部分代码省略.........
示例7: Tk_Nosy
# 需要导入模块: from tkinter import Label [as 别名]
# 或者: from tkinter.Label import cget [as 别名]
class Tk_Nosy(object):
"""This class is the tkinter GUI object"""
# make a collection of python interpreters to choose from
pythonInterpreterCollection = None # will be PyInterpsOnSys object
# extra python interpreters can run nosetests concurrently to main window
# concurrent_versionL contains tuples = (PI, Popup)
concurrent_versionL = [] # additional running python interpreters
def __init__(self, master):
self.dirname = os.path.abspath( os.curdir )
self.initComplete = 0
self.master = master
self.x, self.y, self.w, self.h = -1,-1,-1,-1
# bind master to <Configure> in order to handle any resizing, etc.
# postpone self.master.bind("<Configure>", self.Master_Configure)
self.master.bind('<Enter>', self.bindConfigure)
self.menuBar = Menu(master, relief = "raised", bd=2)
self.menuBar.add("command", label = "Change_Dir", command = self.menu_Directory_Change_Dir)
disp_Choices = Menu(self.menuBar, tearoff=0)
self.display_test_details = StringVar()
self.display_test_details.set('N')
disp_Choices.add_checkbutton(label='Display Test Details', variable=self.display_test_details, onvalue='Y', offvalue='N')
self.display_watched_files = StringVar()
self.display_watched_files.set('N')
disp_Choices.add_checkbutton(label='Show Watched Files', variable=self.display_watched_files, onvalue='Y', offvalue='N')
self.menuBar.add("cascade", label="Display", menu=disp_Choices)
py_choices = Menu(self.menuBar, tearoff=0)
py_choices.add("command", label = "Change Python Version",
command = self.changePythonVersion)
py_choices.add("command", label = "Find New Python Interpreter",
command = self.findNewPythonInterpreter)
py_choices.add("command", label = "Launch Another Python Interpreter",
command = self.launchAnotherPythonInterpreter)
self.menuBar.add("cascade", label="Python", menu=py_choices)
#top_Snippet = Menu(self.menuBar, tearoff=0)
self.menuBar.add("command", label = "Run", command = self.menu_Run)
self.display_test_details.trace("w", self.rerun_tests)
self.display_watched_files.trace("w", self.rerun_tests)
master.config(menu=self.menuBar)
# make a Status Bar
self.statusMessage = StringVar()
self.statusMessage.set(self.dirname)
self.statusbar = Label(self.master, textvariable=self.statusMessage,
bd=1, relief=SUNKEN)
self.statusbar.pack(anchor=SW, fill=X, side=BOTTOM)
self.statusbar_bg = self.statusbar.cget('bg') # save bg for restore
self.arial_12_bold_font = tkinter.font.Font(family="Arial", size=12,
weight=tkinter.font.BOLD)
self.arial_12_font = tkinter.font.Font(family="Arial", size=12)
self.statusbar.config( font=self.arial_12_bold_font )
frame = Frame(master)
frame.pack(anchor=NE, fill=BOTH, side=TOP)
self.Pass_Fail_Button = Button(frame,text="Pass/Fail Will Be Shown Here",
image="", width="15", background="green",
anchor=W, justify=LEFT, padx=2)
self.Pass_Fail_Button.pack(anchor=NE, fill=X, side=TOP)
self.Pass_Fail_Button.bind("<ButtonRelease-1>", self.Pass_Fail_Button_Click)
self.master.title("tk_nosy")
self.oscillator = 1 # animates character on title
self.oscillator_B = 0 # used to return statusbar to statusbar_bg
self.lbframe = Frame( frame )
self.lbframe.pack(anchor=SE, side=LEFT, fill=BOTH, expand=1)
scrollbar = Scrollbar(self.lbframe, orient=VERTICAL)
self.Text_1 = Text(self.lbframe, width="80", height="24",
yscrollcommand=scrollbar.set)
scrollbar.config(command=self.Text_1.yview)
scrollbar.pack(side=RIGHT, fill=Y)
self.Text_1.pack(side=LEFT, fill=BOTH, expand=1)
self.master.resizable(1,1) # Linux may not respect this
self.numNosyCalls = 0
self.need_to_pick_dir = 1
#.........这里部分代码省略.........