本文整理汇总了Python中tkinter.ttk.Label类的典型用法代码示例。如果您正苦于以下问题:Python Label类的具体用法?Python Label怎么用?Python Label使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Label类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Example
class Example(Frame):
def __init__(self, parent):
Frame.__init__(self, parent)
self.parent = parent
self.initUI()
def initUI(self):
self.parent.title("Listbox")
self.pack(fill=BOTH, expand=1)
acts = ['Scarlett Johansson', 'Rachel Weiss',
'Natalie Portman', 'Jessica Alba']
lb = Listbox(self)
for i in acts:
lb.insert(END, i)
lb.bind("<<ListboxSelect>>", self.onSelect)
lb.place(x=20, y=20)
self.var = StringVar()
self.label = Label(self, text=0, textvariable=self.var)
self.label.place(x=20, y=210)
def onSelect(self, val):
sender = val.widget
idx = sender.curselection()
value = sender.get(idx)
self.var.set(value)
示例2: 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)
示例3: Form
class Form(Frame):
def __init__(self, parent):
Frame.__init__(self, parent)
self.parent = parent
self.parent.title("Example Form")
self.pack(fill=BOTH, expand=True)
f = Frame(self)
f.pack(fill=X)
l = Label(f, text='First Name', width=10)
l.pack(side=LEFT, padx=5, pady=5)
self.firstName = Entry(f)
self.firstName.pack(fill=X, padx=5, expand=True)
f = Frame(self)
f.pack(fill=X)
l = Label(f, text='Last Name', width=10)
l.pack(side=LEFT, padx=5, pady=5)
self.lastName = Entry(f)
self.lastName.pack(fill=X, padx=5, expand=True)
f = Frame(self)
f.pack(fill=X)
l = Label(f, text='Full Name', width=10)
l.pack(side=LEFT, padx=5, pady=5)
self.fullName = Label(f, text='ALEX POOPKIN', width=10)
self.fullName.pack(fill=X, padx=5, expand=True)
f = Frame(self)
f.pack(fill=X)
l = Label(f, text='', width=10)
l.pack(side=LEFT, padx=5, pady=0)
self.errorMessage = Label(f, text='Invalid character int the name!', foreground='red', width=30)
self.errorMessage.pack(fill=X, padx=5, expand=True)
f = Frame(self)
f.pack(fill=X)
b = Button(f, text='Close', command=lambda : self.parent.quit())
b.pack(side=RIGHT, padx=5, pady=10)
b['default'] = ACTIVE
b.focus_set()
self.clearButton = Button(f, text='Clear')
self.clearButton.pack(side=RIGHT, padx=5, pady=10)
self.clearButton['state'] = DISABLED
self.sendButton = Button(f, text='Send')
self.sendButton.pack(side=RIGHT, padx=5, pady=10)
示例4: initUI
def initUI(self):
self.parent.title("Windows")
self.style = Style()
self.style.theme_use("default")
self.pack(fill=BOTH, expand=1)
self.columnconfigure(1, weight=1)
self.columnconfigure(3, pad=7)
self.rowconfigure(6, weight=1)
self.rowconfigure(5, pad=7)
lbl = Label(self, text="BookManager")
lbl.grid(sticky=W, pady=4, padx=5)
self.area = Text(self) #WHITE TEXT BOX
self.area.grid(row=1, column=0, columnspan=3, rowspan=4,
padx=5, sticky=E+W+S+N)
abtn = Button(self, text="add", command=self.press_add)
abtn.grid(row=1, column=3)
srcbtn = Button(self, text="search", command=self.press_search)
srcbtn.grid(row=2, column=3, pady=3)
rbtn = Button(self, text="remove", command=self.press_remove)
rbtn.grid(row=3, column=3, pady=3)
sbtn = Button(self, text="show all", command=self.press_show)
sbtn.grid(row=4, column=3, pady=3)
示例5: OkFrame
class OkFrame(MessageFrame):
def __init__(self, master, config):
super(OkFrame, self).__init__(master, config)
if config.full_screen:
self._make_full(master)
self.master.grid_rowconfigure(0, weight=1)
self.master.grid_rowconfigure(1, weight=1)
self.master.grid_columnconfigure(0, weight=1)
self._frame_lbl = Label(
self.master,
text='',
anchor='center',
font=self._config.item_font
)
self._frame_lbl.grid(row=0, column=0, sticky='snew')
self._next_btn = Button(
self.master,
text='OK',
command=self._next_cmd
)
self._next_btn.grid(row=1, column=0, sticky='snew')
def show(master, config, msg):
new_window = Toplevel(master)
dlg = OkFrame(new_window, config)
dlg._frame_lbl['text'] = msg
def _next_cmd(self):
self._master.destroy()
示例6: initUI
def initUI(self):
self.parent.title("Windows")
self.style = Style()
self.style.theme_use("default")
self.pack(fill=BOTH, expand=1)
self.columnconfigure(1, weight=1)
self.columnconfigure(3, pad=7)
self.rowconfigure(3, weight=1)
self.rowconfigure(5, pad=7)
lbl = Label(self, text="Windows")
lbl.grid(sticky=W, pady=4, padx=5)
area = Text(self)
area.grid(row=1, column=0, columnspan=2, rowspan=4, padx=5, sticky=E + W + S + N)
abtn = Button(self, text="Activate")
abtn.grid(row=1, column=3)
cbtn = Button(self, text="Close")
cbtn.grid(row=2, column=3, pady=4)
hbtn = Button(self, text="Help")
hbtn.grid(row=5, column=0, padx=5)
obtn = Button(self, text="OK")
obtn.grid(row=5, column=3)
示例7: 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)
示例8: DateWidget
class DateWidget(Frame):
"""Gets a date from the user."""
def __init__(self, master):
"""Make boxes, register callbacks etc."""
Frame.__init__(self, master)
self.label = Label(self, text="När är du född?")
self.label.pack()
self.entry_text = StringVar()
self.entry_text.trace("w", lambda *args: self.onEntryChanged())
self.entry = Entry(self, width=date_entry_width,
textvariable=self.entry_text)
self.entry.insert(0, "ÅÅÅÅ-MM-DD")
self.entry.pack(pady=small_pad)
self.button = Button(self, text="Uppdatera",
command=lambda: self.onDateChanged())
self.button.pack()
self.entry.focus_set()
self.entry.select_range(0, END)
self.entry.bind("<Return>", lambda x: self.onDateChanged())
def setListener(self, pred_view):
"""Select whom to notify when a new date is entered."""
self.pred_view = pred_view
def onDateChanged(self):
"""Notifies the PredictionWidget that the date has been changed."""
try:
date = datetime.datetime.strptime(self.entry.get(),
"%Y-%m-%d").date()
self.pred_view.update(date)
except ValueError:
self.entry.configure(foreground="red")
def onEntryChanged(self):
"""Reset the text color."""
self.entry.configure(foreground="")
示例9: StatusBar
class StatusBar(TagReaderListener):
def __init__(self, master):
super().__init__()
self.label = Label(master, text='', anchor=W)
self.label.pack()
self.index = 0
self.expected_count = 0
def start_task(self, text):
self.label['text'] = text + "..."
def task_complete(self):
self.label['text'] += 'Done'
def read_complete(self, elapsed_time):
self.set("{} files read in {} milliseconds".format(self.expected_count, round(elapsed_time, 2)))
def read_start(self, count):
self.expected_count = count
self.index = 0
self.set("Reading tags in {} files".format(self.expected_count))
def file_read(self, file):
self.index += 1
percent = round(100 * self.index / self.expected_count, 2)
self.set("Reading tags in {} files: {}%".format(self.expected_count, percent))
def counting_files(self):
self.set("Counting files...")
def set(self, text: str):
self.label['text'] = text
示例10: PredictionWidget
class PredictionWidget(Frame):
"""Shows a prediction to the user."""
def __init__(self, master):
"""Make boxes, register callbacks etc."""
Frame.__init__(self, master)
self.active_category = StringVar()
self.bind("<Configure>", self.onResize)
self.date = None
self.predictor = Predictor()
self.category_buttons = self.createCategoryButtons()
self.text = Label(self, justify=CENTER, font="Arial 14")
def createCategoryButtons(self):
"""Create the buttons used to choose category. Return them."""
result = []
icons = self.readIcons()
categories = self.predictor.categories()
for i in categories:
if i in icons:
icon = icons[i]
else:
icon = icons["= default ="]
category_button = Radiobutton(self, image=icon,
variable=self.active_category, value=i, indicatoron=False,
width=icon_size, height=icon_size, command=self.update)
category_button.image_data = icon
result.append(category_button)
self.active_category.set(categories[0])
return result
def readIcons(self):
"""Read the gui icons from disk. Return them."""
result = {}
categories = open(nextToThisFile("icons.txt")).read().split("\n\n")
for i in categories:
category_name, file_data = i.split("\n", maxsplit=1)
image = PhotoImage(data=file_data)
result[category_name] = image
return result
def onResize(self, event):
"""Rearrange the children when the geometry of self changes."""
if event.widget == self:
center = (event.width / 2, event.height / 2)
radius = min(center) - icon_size / 2
self.text.place(anchor=CENTER, x=center[0], y=center[1])
for i, j in enumerate(self.category_buttons):
turn = 2 * math.pi
angle = turn * (1 / 4 - i / len(self.category_buttons))
j.place(anchor=CENTER,
x=center[0] + math.cos(angle) * radius,
y=center[1] - math.sin(angle) * radius)
def update(self, date=None):
"""Change contents based on circumstances. Set date if given."""
if date:
self.date = date
if self.date:
predictions = self.predictor.predict(self.date)
prediction = predictions[self.active_category.get()]
prediction = textwrap.fill(prediction, width=20)
else:
prediction = ""
self.text.configure(text=prediction)
示例11: __init__
def __init__(self, url):
self.url = url
self.root = Tk()
self.root.title("验证码")
while True:
try:
image_bytes = urlopen(self.url).read()
break
except socket.timeout:
print('获取验证码超时:%s\r\n重新获取.' % (self.url))
continue
except urllib.error.URLError as e:
if isinstance(e.reason, socket.timeout):
print('获取验证码超时:%s\r\n重新获取.' % (self.url))
continue
# internal data file
data_stream = io.BytesIO(image_bytes)
# open as a PIL image object
self.pil_image = Image.open(data_stream)
# convert PIL image object to Tkinter PhotoImage object
self.tk_image = ImageTk.PhotoImage(self.pil_image)
self.label = Label(self.root, image=self.tk_image, background='brown')
self.label.pack(padx=5, pady=5)
self.button = Button(self.root, text="刷新验证码", command=self.refreshImg)
self.button.pack(padx=5, pady=5)
randCodeLable = Label(self.root, text="验证码:")
randCodeLable.pack(padx=5, pady=5)
self.randCode = Entry(self.root)
self.randCode.pack(padx=5, pady=5)
self.loginButton = Button(self.root, text="登录", default=tkinter.ACTIVE)
self.loginButton.pack(padx=5, pady=5)
示例12: create_widgets
def create_widgets(self): # Call from override, if any.
# Bind to self widgets needed for entry_ok or unittest.
self.frame = frame = Frame(self, padding=10)
frame.grid(column=0, row=0, sticky='news')
frame.grid_columnconfigure(0, weight=1)
entrylabel = Label(frame, anchor='w', justify='left',
text=self.message)
self.entryvar = StringVar(self, self.text0)
self.entry = Entry(frame, width=30, textvariable=self.entryvar)
self.entry.focus_set()
self.error_font = Font(name='TkCaptionFont',
exists=True, root=self.parent)
self.entry_error = Label(frame, text=' ', foreground='red',
font=self.error_font)
self.button_ok = Button(
frame, text='OK', default='active', command=self.ok)
self.button_cancel = Button(
frame, text='Cancel', command=self.cancel)
entrylabel.grid(column=0, row=0, columnspan=3, padx=5, sticky=W)
self.entry.grid(column=0, row=1, columnspan=3, padx=5, sticky=W+E,
pady=[10,0])
self.entry_error.grid(column=0, row=2, columnspan=3, padx=5,
sticky=W+E)
self.button_ok.grid(column=1, row=99, padx=5)
self.button_cancel.grid(column=2, row=99, padx=5)
示例13: __init__
def __init__(self, pipepanel, pipeline_name, *args, **kwargs) :
PipelineFrame.__init__(self, pipepanel, pipeline_name, *args, **kwargs)
self.pairs = None
eframe = self.eframe = LabelFrame(self,text="Options")
#,fg=textLightColor,bg=baseColor)
eframe.grid( row=5, column=1, sticky=W, columnspan=7, padx=10, pady=5 )
label = Label(eframe,text="Pipeline")#,fg=textLightColor,bg=baseColor)
label.grid(row=3,column=0,sticky=W,padx=10,pady=5)
PipelineLabels = ['Initial QC',
'Germline',
'Somatic Tumor-Normal',
'Somatic Tumor-Only']
Pipelines=["initialqcgenomeseq",
"wgslow",
'wgs-somatic',
'wgs-somatic-tumoronly']
self.label2pipeline = { k:v for k,v in zip(PipelineLabels, Pipelines)}
PipelineLabel = self.PipelineLabel = StringVar()
Pipeline = self.Pipeline = StringVar()
PipelineLabel.set(PipelineLabels[0])
#om = OptionMenu(eframe, Pipeline, *Pipelines, command=self.option_controller)
om = OptionMenu(eframe, PipelineLabel, *PipelineLabels, command=self.option_controller)
om.config()#bg = widgetBgColor,fg=widgetFgColor)
om["menu"].config()#bg = widgetBgColor,fg=widgetFgColor)
#om.pack(side=LEFT,padx=20,pady=5)
om.grid(row=3,column=1,sticky=W,padx=10,pady=5)
示例14: build_widgets
def build_widgets(self):
"Build the various widgets that will be used in the program."
# Create processing frame widgets.
self.processing_frame = LabelFrame(self, text='Processing Mode:')
self.mode_var = StringVar(self, 'encode')
self.decode_button = Radiobutton(self.processing_frame,
text='Decode Cipher-Text',
command=self.handle_radiobuttons,
value='decode',
variable=self.mode_var)
self.encode_button = Radiobutton(self.processing_frame,
text='Encode Plain-Text',
command=self.handle_radiobuttons,
value='encode',
variable=self.mode_var)
self.freeze_var = BooleanVar(self, False)
self.freeze_button = Checkbutton(self.processing_frame,
text='Freeze Key & Primer',
command=self.handle_checkbutton,
offvalue=False,
onvalue=True,
variable=self.freeze_var)
# Create encoding frame widgets.
self.encoding_frame = LabelFrame(self, text='Encoding Options:')
self.chain_size_label = Label(self.encoding_frame, text='Chain Size:')
self.chain_size_entry = Entry(self.encoding_frame)
self.plain_text_label = Label(self.encoding_frame, text='Plain-Text:')
self.plain_text_entry = Entry(self.encoding_frame)
# Create input frame widgets.
self.input_frame = LabelFrame(self, text='Input Area:')
self.input_text = ScrolledText(self.input_frame, **self.TEXT)
# Create output frame widgets.
self.output_frame = LabelFrame(self, text='Output Area:')
self.output_text = ScrolledText(self.output_frame, **self.TEXT)
示例15: setup_gui
def setup_gui(self):
self.parent.title("Stein - Saks - Papir")
self.style.theme_use("default")
self.pack(fill=BOTH, expand=1)
# Label for rapportering
label = Label(self.parent, textvariable=self.resultat_label)
label.place(x=800, y=50)
# Buttons
# Disse fyrer av metoden self.arranger_enkeltspill som er
# definert i klassen. Denne metoden tar aksjonen til mennesket
# som startup, og gjennomfoerer spillet
# Samme type oppfoersel for de tre aksjons-knappene
rock_button = Button(self, text="Stein",
command=lambda: self.arranger_enkeltspill(Action("rock")))
rock_button.place(x=800, y=400)
scissors_button = Button(self, text="Saks",
command=lambda: self.arranger_enkeltspill(Action("scissor")))
scissors_button.place(x=900, y=400)
paper_button = Button(self, text="Papir",
command=lambda: self.arranger_enkeltspill(Action("paper")))
paper_button.place(x=1000, y=400)
# quit_button avslutter GUI'et naar den trykkes
quit_button = Button(self, text="Quit", command=self.quit)
quit_button.place(x=1000, y=450)
# Embedde en graf i vinduet for aa rapportere fortloepende score
self.fig = FigureCanvasTkAgg(pylab.figure(), master=self)
self.fig.get_tk_widget().grid(column=0, row=0)
self.fig.show()