本文整理汇总了Python中tkinter.ttk.Label.place方法的典型用法代码示例。如果您正苦于以下问题:Python Label.place方法的具体用法?Python Label.place怎么用?Python Label.place使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tkinter.ttk.Label
的用法示例。
在下文中一共展示了Label.place方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Example
# 需要导入模块: from tkinter.ttk import Label [as 别名]
# 或者: from tkinter.ttk.Label import place [as 别名]
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: PredictionWidget
# 需要导入模块: from tkinter.ttk import Label [as 别名]
# 或者: from tkinter.ttk.Label import place [as 别名]
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)
示例3: setup_gui
# 需要导入模块: from tkinter.ttk import Label [as 别名]
# 或者: from tkinter.ttk.Label import place [as 别名]
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()
示例4: initUI
# 需要导入模块: from tkinter.ttk import Label [as 别名]
# 或者: from tkinter.ttk.Label import place [as 别名]
def initUI(self):
# Initialize and name Window
self.parent.title("Poly Pocket")
self.style = Style()
self.style.theme_use("default")
self.pack(fill=BOTH, expand=1)
def new_baseline():
return
def old_baseline():
return
def test(baseline):
return
def spark_connect():
return
def leap_connect():
return
def quit():
self.parent.destroy()
return
welcome = "Welcome to Poly Pocket!"
welcome_label = Label(self, text=welcome, font=("Helvetica", 24))
welcome_label.place(x=5, y=5)
welcome_label.pack()
baseline_button = Button(self, text="New Baseline",
command=new_baseline())
recover_baseline_button = Button(self, text="Recover Baseline",
command=old_baseline())
test_button = Button(self, text="Conduct Test",
command=test(self.baseline))
connect_leap_button = Button(self, text="Establish Leap Connection",
command=leap_connect)
connect_spark_button = Button(self, text="Establish Spark Connection",
command=spark_connect)
exit_button = Button(self, text="Quit",
command=quit)
baseline_button.place(relx=0.5, rely=0.3, anchor=CENTER)
recover_baseline_button.place(relx=0.5, rely=0.4, anchor=CENTER)
test_button.place(relx=0.5, rely=0.5, anchor=CENTER)
connect_leap_button.place(relx=0.5, rely=0.6, anchor=CENTER)
connect_spark_button.place(relx=0.5, rely=0.7, anchor=CENTER)
exit_button.place(relx=0.5, rely = 0.8, anchor=CENTER)
示例5: Pencil
# 需要导入模块: from tkinter.ttk import Label [as 别名]
# 或者: from tkinter.ttk.Label import place [as 别名]
class Pencil(Frame): # pylint: disable=too-many-ancestors
"""A smaller box (of 0-9) representing the pencil marks in a normal box."""
def __init__(self, master):
"""Construct a Pencil frame with parent master.
Args:
master: The parent frame.
"""
Frame.__init__(self, master, width=10, height=10, style=styles.BOX_FRAME)
self.position = (0, 0)
self.number_value = ' '
self.number_text = StringVar(self, ' ')
self.label = Label(self, textvariable=self.number_text, style=styles.PENCIL_LABEL)
self.label.place(relx=0.5, rely=0.5, anchor='center')
def place_at_position(self, position):
"""Places this frame in its parent at the given position.
Args:
position: Tuple of (x, y) for the position to place at.
"""
row = position[0]
col = position[1]
self.position = position
frame_index = row * 3 + col
self.number_value = str(frame_index + 1)
def show(self, flag):
"""Show or hide the pencil frame, based on the flag.
Args:
flag: `True` to show this pencil mark, `False` to hide it.
"""
self.number_text.set(self.number_value if flag else ' ')
示例6: Box
# 需要导入模块: from tkinter.ttk import Label [as 别名]
# 或者: from tkinter.ttk.Label import place [as 别名]
class Box(Frame): # pylint: disable=too-many-ancestors
"""Represents a single box (of 0-9) in the sudoku board."""
_counter = 0
def __init__(self, master):
"""Construct a Box frame with parent master.
Args:
master: The parent frame.
"""
Frame.__init__(self, master, style=styles.BOX_FRAME)
self.position = (0, 0)
self.binding_tag = 'BoxFrame' + str(Box._counter)
self.number_text = StringVar(self, '')
Box._counter += 1
self.borders = dict()
for edge in 'nesw':
self.borders[edge] = Border(self, edge)
self.inner_frame = Frame(self, width=30, height=30, style=styles.BOX_FRAME)
self.pencil_marks = _build_3x3_grid(self.inner_frame, Pencil)
self.label = Label(self.inner_frame, textvariable=self.number_text, style=styles.NUMBER_LABEL)
_tag_widget(self, self.binding_tag)
_tag_widget(self.inner_frame, self.binding_tag)
_tag_widget(self.label, self.binding_tag)
for mark in self.pencil_marks:
_tag_widget(mark, self.binding_tag)
_tag_widget(mark.label, self.binding_tag)
def place_at_position(self, position):
"""Places this frame in its parent at the given position.
Args:
position: Tuple of (x, y) for the position to place at.
parent_position: Tuple of (x, y) for the position the parent is in relative to the grandparent.
"""
row = position[0]
col = position[1]
parent_position = self.master.position # master "ought to be" SubGrid
self.position = (parent_position[0] * 3 + row, parent_position[1] * 3 + col)
padx = (0, _BOX_PADDING) if col < 2 else 0
pady = (0, _BOX_PADDING) if row < 2 else 0
self.grid(row=row, column=col, padx=padx, pady=pady, sticky='nesw')
self.inner_frame.pack(padx=_BORDER_WIDTH, pady=_BORDER_WIDTH, expand=True)
self.number = 0
@property
def number(self):
"""The number the box contains. Setting this value may change the box's style."""
try:
return int(self.number_text.get())
except ValueError:
return 0
@number.setter
def number(self, value):
for pencil_mark in self.pencil_marks:
pencil_mark.grid_forget()
self['style'] = styles.BOX_FRAME
self.inner_frame['style'] = styles.BOX_FRAME
self.label['style'] = styles.NUMBER_LABEL
self.label.place(relx=0.5, rely=0.5, anchor='center')
self.number_text.set(str(value or ' ')[0])
@property
def given(self):
"""The given value for this box. Setting this value may change the box's style."""
if self['style'] != styles.GIVEN_FRAME:
return 0
else:
return self.number
@given.setter
def given(self, value):
for pencil_mark in self.pencil_marks:
pencil_mark.grid_forget()
self['style'] = styles.GIVEN_FRAME
self.inner_frame['style'] = styles.GIVEN_FRAME
self.label['style'] = styles.GIVEN_LABEL
self.label.place(relx=0.5, rely=0.5, anchor='center')
self.number_text.set(str(value or ' ')[0])
def set_pencils(self, values=0b111111111):
"""Sets the box's pencils to showing.
Args:
values: Which pencil marks to display.
Bit0 set means display the '1' pencil mark, bit1 set means display the '2' pencil mark, etc.
"""
self.label.place_forget()
self['style'] = styles.BOX_FRAME
self.inner_frame['style'] = styles.BOX_FRAME
#.........这里部分代码省略.........