当前位置: 首页>>代码示例>>Python>>正文


Python Frame.winfo_reqheight方法代码示例

本文整理汇总了Python中Tkinter.Frame.winfo_reqheight方法的典型用法代码示例。如果您正苦于以下问题:Python Frame.winfo_reqheight方法的具体用法?Python Frame.winfo_reqheight怎么用?Python Frame.winfo_reqheight使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Tkinter.Frame的用法示例。


在下文中一共展示了Frame.winfo_reqheight方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: Chord

# 需要导入模块: from Tkinter import Frame [as 别名]
# 或者: from Tkinter.Frame import winfo_reqheight [as 别名]
class Chord(Frame):
    RIGHT_ARROW_ICON = 'I2RlZmluZSBpbWFnZV93aWR0aCAxNwojZGVmaW5lIGltYWdlX2hlaWdodCAxNwpzdGF0aWMgY2hhciBpbWFnZV9iaXRzW10gPSB7CjB4MDAsMHgwMCwweDAwLDB4MDAsMHgwMCwweDAwLDB4MDAsMHgwMCwweDAwLDB4MDAsMHgwMCwweDAwLDB4MDAsMHgwMCwweDAwLAoweDYwLDB4MDAsMHgwMCwweGUwLDB4MDAsMHgwMCwweGUwLDB4MDMsMHgwMCwweGUwLDB4MGYsMHgwMCwweGUwLDB4MDMsMHgwMCwKMHhlMCwweDAxLDB4MDAsMHg2MCwweDAwLDB4MDAsMHgwMCwweDAwLDB4MDAsMHgwMCwweDAwLDB4MDAsMHgwMCwweDAwLDB4MDAsCjB4MDAsMHgwMCwweDAwLDB4MDAsMHgwMCwweDAwCn07'
    DOWN_ARROW_ICON = 'I2RlZmluZSBpbWFnZV93aWR0aCAxNwojZGVmaW5lIGltYWdlX2hlaWdodCAxNwpzdGF0aWMgY2hhciBpbWFnZV9iaXRzW10gPSB7CjB4MDAsMHgwMCwweDAwLDB4MDAsMHgwMCwweDAwLDB4MDAsMHgwMCwweDAwLDB4MDAsMHgwMCwweDAwLDB4MDAsMHgwMCwweDAwLAoweDAwLDB4MDAsMHgwMCwweGUwLDB4MGYsMHgwMCwweGUwLDB4MGYsMHgwMCwweGMwLDB4MDcsMHgwMCwweGMwLDB4MDMsMHgwMCwKMHg4MCwweDAzLDB4MDAsMHgwMCwweDAxLDB4MDAsMHgwMCwweDAxLDB4MDAsMHgwMCwweDAwLDB4MDAsMHgwMCwweDAwLDB4MDAsCjB4MDAsMHgwMCwweDAwLDB4MDAsMHgwMCwweDAwCn07'

    def __init__(self, master, title, width, body_background="white", background="#f0f0f0", foreground="#333333", selected_background="#1ba1e2", selected_foreground="white", active_foreground="#0067cb", cursor="hand1"):
        Frame.__init__(self, master, background="white")
        self._title = title

        self._background = background
        self._foreground = foreground
        self._active_foreground = active_foreground
        self._selected_foreground = selected_foreground
        self._selected_background = selected_background

        self._cursor = cursor
        
        self._right_arrow_icon = BitmapImage(data=base64.b64decode(Chord.RIGHT_ARROW_ICON))
        self._down_arrow_icon = BitmapImage(data=base64.b64decode(Chord.DOWN_ARROW_ICON))
        
        self._caption = Frame(self, width =width, background=background, padx=2)
        self._caption.pack(fill=X, pady=(0,2))
        self._caption.pack_propagate(False)

        self._icon_label = Label(self._caption, image=self._right_arrow_icon, background=background)
        self._icon_label.pack(side=LEFT)

        self._title_label = Label(self._caption, text=title, bg = background, fg=foreground)
        self._title_label.pack(side=LEFT, padx=4, fill=X)

        self._caption.configure(height= self._title_label.winfo_reqheight())

        self.body = Frame(self, background=body_background)
        self._body_height = None

        self._is_opened = False
        self._is_animating = False

        self._caption.bind('<Button-1>', self._on_click)
        self._title_label.bind('<Button-1>', self._on_click)
        self._icon_label.bind('<Button-1>', self._on_click)

        self._caption.bind('<Enter>', self._on_enter)
        self._caption.bind('<Leave>', self._on_leave)
    
    @property
    def title(self):
        return self._title
        
    @title.setter
    def title(self, text):
        self._title = text
        self._title_label.configure(text=text)

    def _on_enter(self, event):
        if not self._is_opened:
            self._down_arrow_icon.configure(foreground=self._active_foreground)
            self._right_arrow_icon.configure(foreground=self._active_foreground)

        self.config(cursor=self._cursor)

    def _on_leave(self, event):
        if not self._is_opened:
            self._down_arrow_icon.configure(foreground=self._foreground)
            self._right_arrow_icon.configure(foreground=self._foreground)
        
        self.config(cursor="arrow")

    def _on_click(self, event):
        if self._is_animating: return

        self.toggle()

    def open(self):
        if self._is_animating: return

        if not self._is_opened: self._open()

    def _open(self):        
        self.body.pack()
        self.body.pack_propagate(False)
        
        self._icon_label.configure(image=self._down_arrow_icon, background = self._selected_background)
        self._title_label.configure(foreground= self._selected_foreground, background = self._selected_background)
        self._caption.configure(background = self._selected_background)
        
        self._down_arrow_icon.configure(foreground=self._selected_foreground)

        if self._body_height is None:
            self._body_height= self.body.winfo_reqheight()

        end_value = self._body_height

        self.body.configure(width=self.winfo_width())
        self._is_opened = True
        self._is_animating = True

        animation = Animation(
            self,
            ticks=16,
            interval_time=0.01,
#.........这里部分代码省略.........
开发者ID:jacob-carrier,项目名称:code,代码行数:103,代码来源:recipe-580781.py

示例2: CollapsibleFrame

# 需要导入模块: from Tkinter import Frame [as 别名]
# 或者: from Tkinter.Frame import winfo_reqheight [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()
开发者ID:jacob-carrier,项目名称:code,代码行数:93,代码来源:recipe-580760.py


注:本文中的Tkinter.Frame.winfo_reqheight方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。