本文整理汇总了Python中Tkinter.Frame.pack_slaves方法的典型用法代码示例。如果您正苦于以下问题:Python Frame.pack_slaves方法的具体用法?Python Frame.pack_slaves怎么用?Python Frame.pack_slaves使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Tkinter.Frame
的用法示例。
在下文中一共展示了Frame.pack_slaves方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Row_Header
# 需要导入模块: from Tkinter import Frame [as 别名]
# 或者: from Tkinter.Frame import pack_slaves [as 别名]
class Row_Header(Canvas):
def __init__(self, master, font, row_height, row_minwidth, hover_background=None, background=None, anchor=None, onclick=None):
Canvas.__init__(self, master, bd=0, highlightthickness=0, yscrollincrement=row_height, width=0)
if background is not None:
self.configure(background=background)
self._frame_of_row_numbers = Frame(self, bd=0)
self.create_window(0, 0, window=self._frame_of_row_numbers, anchor=N+W)
self._width_of_row_numbers = 0
self._labelrow_kwargs = labelrow_kwargs= {}
labelrow_kwargs["font"] = font
if anchor is not None:
labelrow_kwargs["anchor"] = anchor
self._row_minwidth= row_minwidth
self._row_height = row_height
self._hover_background = hover_background
self._onclick = onclick
self._number_of_labels = 0
def pop(self, n_labels=1):
if self._number_of_labels == 0:
return
list_of_slaves = self._frame_of_row_numbers.pack_slaves()
for i in range(n_labels):
list_of_slaves.pop().destroy()
if list_of_slaves:
width_of_row_numbers= max(list_of_slaves[-1].winfo_reqwidth(), self._row_minwidth)
if width_of_row_numbers < self._width_of_row_numbers:
self._width_of_row_numbers = width_of_row_numbers
for slave in self._frame_of_row_numbers.pack_slaves():
slave.configure(width=width_of_row_numbers)
self.config(width=self._frame_of_row_numbers.winfo_reqwidth())
self.config(scrollregion=(0, 0, self._frame_of_row_numbers.winfo_reqwidth(), len(list_of_slaves)*self._row_height))
self._number_of_labels -= n_labels
def delete_labels(self):
if self._number_of_labels == 0:
return
for slave in self._frame_of_row_numbers.pack_slaves():
slave.destroy()
self._number_of_labels = 0
def new_label(self):
# Creating a new row header
self._number_of_labels += 1
frame_button = Frame(self._frame_of_row_numbers, height=self._row_height)
frame_button.pack()
frame_button.pack_propagate(False)
row_label = Label(frame_button, text =self._number_of_labels, **self._labelrow_kwargs)
row_label.bind("<1>", lambda event, index=self._number_of_labels-1: self._on_click_label(index))
if self._hover_background:
row_label.bind("<Enter>", lambda event, row_label=row_label: row_label.configure(background=self._hover_background))
row_label.bind("<Leave>", lambda event, row_label=row_label: row_label.configure(background=self.cget("background")))
row_label.pack(expand=True, fill=BOTH)
width_of_row_numbers= max(row_label.winfo_reqwidth(), self._row_minwidth)
if width_of_row_numbers > self._width_of_row_numbers:
self._width_of_row_numbers = width_of_row_numbers
for slave in self._frame_of_row_numbers.pack_slaves():
slave.configure(width=width_of_row_numbers)
else:
frame_button.configure(width=width_of_row_numbers)
frame_button.update_idletasks()
self.config(width=self._frame_of_row_numbers.winfo_reqwidth())
self.config(scrollregion=(0, 0, self._frame_of_row_numbers.winfo_reqwidth(), self._number_of_labels*self._row_height))
def _on_click_label(self, index):
if self._onclick:
self._onclick(index)