本文整理汇总了Python中Tkinter.Frame.winfo_reqwidth方法的典型用法代码示例。如果您正苦于以下问题:Python Frame.winfo_reqwidth方法的具体用法?Python Frame.winfo_reqwidth怎么用?Python Frame.winfo_reqwidth使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Tkinter.Frame
的用法示例。
在下文中一共展示了Frame.winfo_reqwidth方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Row_Header
# 需要导入模块: from Tkinter import Frame [as 别名]
# 或者: from Tkinter.Frame import winfo_reqwidth [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)
示例2: Table
# 需要导入模块: from Tkinter import Frame [as 别名]
# 或者: from Tkinter.Frame import winfo_reqwidth [as 别名]
class Table(Frame):
def __init__(self, master, columns, column_weights=None, column_minwidths=None, height=500, minwidth=20, minheight=20, padx=5, pady=5, cell_font=None, cell_foreground="black", cell_background="white", cell_anchor=W, header_font=None, header_background="white", header_foreground="black", header_anchor=CENTER, bordercolor = "#999999", innerborder=True, outerborder=True, stripped_rows=("#EEEEEE", "white"), on_change_data=None, mousewheel_speed = 2, scroll_horizontally=False, scroll_vertically=True):
outerborder_width = 1 if outerborder else 0
Frame.__init__(self,master, bd= 0)
self._cell_background = cell_background
self._cell_foreground = cell_foreground
self._cell_font = cell_font
self._cell_anchor = cell_anchor
self._stripped_rows = stripped_rows
self._padx = padx
self._pady = pady
self._bordercolor = bordercolor
self._innerborder_width = 1 if innerborder else 0
self._data_vars = []
self._columns = columns
self._number_of_rows = 0
self._number_of_columns = len(columns)
self.grid_columnconfigure(0, weight=1)
self.grid_rowconfigure(1, weight=1)
self._head = Frame(self, highlightbackground=bordercolor, highlightcolor=bordercolor, highlightthickness=outerborder_width, bd= 0)
self._head.grid(row=0, column=0, sticky=E+W)
header_separator = False if outerborder else True
for j in range(len(columns)):
column_name = columns[j]
header_cell = Header_Cell(self._head, text=column_name, borderwidth=self._innerborder_width, font=header_font, background=header_background, foreground=header_foreground, padx=padx, pady=pady, bordercolor=bordercolor, anchor=header_anchor, separator=header_separator)
header_cell.grid(row=0, column=j, sticky=N+E+W+S)
add_scrollbars = scroll_horizontally or scroll_vertically
if add_scrollbars:
if scroll_horizontally:
xscrollbar = Scrollbar(self, orient=HORIZONTAL)
xscrollbar.grid(row=2, column=0, sticky=E+W)
else:
xscrollbar = None
if scroll_vertically:
yscrollbar = Scrollbar(self, orient=VERTICAL)
yscrollbar.grid(row=1, column=1, sticky=N+S)
else:
yscrollbar = None
scrolling_area = Scrolling_Area(self, width=self._head.winfo_reqwidth(), height=height, scroll_horizontally=scroll_horizontally, xscrollbar=xscrollbar, scroll_vertically=scroll_vertically, yscrollbar=yscrollbar)
scrolling_area.grid(row=1, column=0, sticky=E+W)
self._body = Frame(scrolling_area.innerframe, highlightbackground=bordercolor, highlightcolor=bordercolor, highlightthickness=outerborder_width, bd= 0)
self._body.pack()
def on_change_data():
scrolling_area.update_viewport()
else:
self._body = Frame(self, height=height, highlightbackground=bordercolor, highlightcolor=bordercolor, highlightthickness=outerborder_width, bd= 0)
self._body.grid(row=1, column=0, sticky=N+E+W+S)
if column_weights is None:
for j in range(len(columns)):
self._body.grid_columnconfigure(j, weight=1)
else:
for j, weight in enumerate(column_weights):
self._body.grid_columnconfigure(j, weight=weight)
if column_minwidths is not None:
for j, minwidth in enumerate(column_minwidths):
if minwidth is None:
header_cell = self._head.grid_slaves(row=0, column=j)[0]
minwidth = header_cell.winfo_reqwidth()
self._body.grid_columnconfigure(j, minsize=minwidth)
else:
for j in range(len(columns)):
header_cell = self._head.grid_slaves(row=0, column=j)[0]
minwidth = header_cell.winfo_reqwidth()
self._body.grid_columnconfigure(j, minsize=minwidth)
self._on_change_data = on_change_data
def _append_n_rows(self, n):
number_of_rows = self._number_of_rows
number_of_columns = self._number_of_columns
for i in range(number_of_rows, number_of_rows+n):
list_of_vars = []
for j in range(number_of_columns):
var = StringVar()
list_of_vars.append(var)
#.........这里部分代码省略.........
示例3: __init__
# 需要导入模块: from Tkinter import Frame [as 别名]
# 或者: from Tkinter.Frame import winfo_reqwidth [as 别名]
#.........这里部分代码省略.........
except AttributeError:
pass
else:
self.edit_finish()
try:
label = self.label
except AttributeError:
self.frame = Frame(self.canvas, border=1, relief='flat')
self.iconlabel = Label(self.frame, image=image, bd=0, padx=1, pady=1, anchor=W)
self.label = Label(self.frame, text=text, bd=0, padx=3, pady=1, anchor=W)
self.iconlabel.pack(side='left')
self.label.pack(side='left', fill='y')
widgets=[self.label,self.iconlabel, self.frame]
if self.evenodd:
bgcolor=self.colortheme.evencolor
else:
bgcolor=self.colortheme.editfieldbackground
for widget in widgets:
if self.selected:
widget['bg']=self.colortheme.selectbackground
else:
widget['bg']=bgcolor
if self.selected:
self.label['fg']=self.colortheme.selectforeground
else:
self.label['fg']=self.colortheme.foreground
width=self.frame.winfo_reqwidth()
if width < self.canvas.winfo_width()-textx:
width = self.canvas.winfo_width()-textx
id = self.canvas.create_window(textx, texty, anchor=NW, window=self.frame, width=width)
self.canvas.windows.append((id,textx))
self.label.bind("<1>", self.select_or_edit)
self.label.bind("<Double-1>", self.flip)
self.iconlabel.bind("<1>", self.select_or_edit)
self.iconlabel.bind("<Double-1>", self.flip)
self.frame.bind("<1>", self.select_or_edit)
self.frame.bind("<Double-1>", self.flip)
self.label.bind("<Button-4>", self.unit_up)
self.label.bind("<Button-5>", self.unit_down)
self.iconlabel.bind("<Button-4>", self.unit_up)
self.iconlabel.bind("<Button-5>", self.unit_down)
self.frame.bind("<Button-4>", self.unit_up)
self.frame.bind("<Button-5>", self.unit_down)
self.text_id = id
def unit_up(self, event):
first,last=self.canvas.yview()
if first <= 0 and last >= 1:
return "break"
self.canvas.yview_scroll(-1, "unit")
return "break"
def unit_down(self, event):
first,last=self.canvas.yview()
if first <= 0 and last >= 1:
return "break"
self.canvas.yview_scroll(1, "unit")
return "break"
示例4: CollapsibleFrame
# 需要导入模块: from Tkinter import Frame [as 别名]
# 或者: from Tkinter.Frame import winfo_reqwidth [as 别名]
class CollapsibleFrame(Frame):
def __init__(self, master, text=None, borderwidth=2, width=0, height=16, interior_padx=0, interior_pady=8, background=None, caption_separation=4, caption_font=None, caption_builder=None, icon_x=5):
Frame.__init__(self, master)
if background is None:
background = self.cget("background")
self.configure(background=background)
self._is_opened = False
self._interior_padx = interior_padx
self._interior_pady = interior_pady
self._iconOpen = PhotoImage(data="R0lGODlhEAAQAKIAAP///9TQyICAgEBAQAAAAAAAAAAAAAAAACwAAAAAEAAQAAADNhi63BMgyinFAy0HC3Xj2EJoIEOM32WeaSeeqFK+say+2azUi+5ttx/QJeQIjshkcsBsOp/MBAA7")
self._iconClose = PhotoImage(data="R0lGODlhEAAQAKIAAP///9TQyICAgEBAQAAAAAAAAAAAAAAAACwAAAAAEAAQAAADMxi63BMgyinFAy0HC3XjmLeA4ngpRKoSZoeuDLmo38mwtVvKu93rIo5gSCwWB8ikcolMAAA7")
height_of_icon = max(self._iconOpen.height(), self._iconClose.height())
width_of_icon = max(self._iconOpen.width(), self._iconClose.width())
containerFrame_pady = (height_of_icon//2) +1
self._height = height
self._width = width
self._containerFrame = Frame(self, borderwidth=borderwidth, width=width, height=height, relief=RIDGE, background=background)
self._containerFrame.pack(expand=True, fill=X, pady=(containerFrame_pady,0))
self.interior = Frame(self._containerFrame, background=background)
self._collapseButton = Label(self, borderwidth=0, image=self._iconOpen, relief=RAISED)
self._collapseButton.place(in_= self._containerFrame, x=icon_x, y=-(height_of_icon//2), anchor=N+W, bordermode="ignore")
self._collapseButton.bind("<Button-1>", lambda event: self.toggle())
if caption_builder is None:
self._captionLabel = Label(self, anchor=W, borderwidth=1, text=text)
if caption_font is not None:
self._captionLabel.configure(font=caption_font)
else:
self._captionLabel = caption_builder(self)
if not isinstance(self._captionLabel, Widget):
raise Exception("'caption_builder' doesn't return a tkinter widget")
self.after(0, lambda: self._place_caption(caption_separation, icon_x, width_of_icon))
def update_width(self, width=None):
# Update could be devil
# http://wiki.tcl.tk/1255
self.after(0, lambda width=width:self._update_width(width))
def _place_caption(self, caption_separation, icon_x, width_of_icon):
self.update()
x = caption_separation + icon_x + width_of_icon
y = -(self._captionLabel.winfo_reqheight()//2)
self._captionLabel.place(in_= self._containerFrame, x=x, y=y, anchor=N+W, bordermode="ignore")
def _update_width(self, width):
self.update()
if width is None:
width=self.interior.winfo_reqwidth()
if isinstance(self._interior_pady, (list, tuple)):
width += self._interior_pady[0] + self._interior_pady[1]
else:
width += 2*self._interior_pady
width = max(self._width, width)
self._containerFrame.configure(width=width)
def open(self):
self._collapseButton.configure(image=self._iconClose)
self._containerFrame.configure(height=self.interior.winfo_reqheight())
self.interior.pack(expand=True, fill=X, padx=self._interior_padx, pady =self._interior_pady)
self._is_opened = True
def close(self):
self.interior.pack_forget()
self._containerFrame.configure(height=self._height)
self._collapseButton.configure(image=self._iconOpen)
self._is_opened = False
def toggle(self):
if self._is_opened:
self.close()
else:
self.open()