在scrolledframe tkinter中显示Treeview小部件

时间:2018-06-26 14:03:31

标签: python tkinter

我运行python 3.6.5(v3.6.5:f59c0932b4,2018年3月28日,16:07:46)[MSC v.1900 32位(Intel)] 和tkinter 8.6。

我有以下代码:

import tkinter as tk
from tkinter import ttk
import Pmw

class GUI():
    def __init__(self, root):
        self.root = root
        self.device_screen_width = self.root.winfo_screenwidth()
        self.device_screen_height = self.root.winfo_screenheight()
        self.app_screen_width = min(800, self.device_screen_width)
        self.app_screen_height = min(600, self.device_screen_height)
        self.app_position_x = int((self.device_screen_width - self.app_screen_width) / 2)
        self.app_position_y = 50
        self.root.geometry("{}x{}+{}+{}".format(self.app_screen_width, self.app_screen_height, \
                                                self.app_position_x, self.app_position_y))

        # Create page main frame
        self.page_frame = tk.Frame(self.root)

        # Create paned window
        self.paned_w = ttk.Panedwindow(self.page_frame, orient='horizontal')

        # Create left frame for the treeview
        self.left_side_frame = Pmw.ScrolledFrame(self.paned_w,
                                                borderframe=0,
                                                horizflex='expand',
                                                scrollmargin=0)

        self.left_side_frame_int = self.left_side_frame.interior()

        # Create treeview
        s = ttk.Style()
        s.configure('Treeview', font='Courier 10', rowheight=15)
        self.treeview = ttk.Treeview(self.left_side_frame_int,
                                     style='Treeview',
                                     selectmode='extended',
                                     columns='questions',
                                     show='headings')
        # Populate treeview
        rows = 10
        for i in range(rows):
            row = i * 'a' + str(i)
            self.treeview.insert("", 'end', text=i, values=row)

        self.treeview.column('#0', width=5, stretch=True)
        self.treeview.heading("questions")
        self.treeview.column("questions", width=200, stretch=True)
        self.treeview['height'] = rows

        # Pack everything in left
        self.page_frame.pack(expand=1, fill='both')
        self.paned_w.pack(expand=1, fill='both')
        self.left_side_frame.pack(expand=1, fill='both')
        self.left_side_frame_int.pack(expand=1, fill='both')
        self.treeview.pack(expand=1, fill='both')

        # Add left pane
        self.paned_w.add(self.left_side_frame)

        # Create right frame
        self.right_side_frame = tk.Frame(self.paned_w)

        # Create label
        self.lbl = tk.Label(self.right_side_frame, text="Label", font="Helvetica 50 bold", bg='red')

        # Pack everything in right
        self.right_side_frame.pack(expand=1, fill='y')
        self.lbl.pack(expand=1, fill='both', padx=0, pady=0)

        # Add right pane
        self.paned_w.add(self.right_side_frame)

if __name__ == '__main__':
    root = tk.Tk()
    app = GUI(root)
    root.mainloop()

第一个问题。有没有一种方法可以显示在窗口y轴的所有空间上展开的treeview小部件,而不管它有多少个项目?

第二个问题。如何实现以下行为:当左窗格的内容扩展的宽度大于预定义的左窗格宽度时,左窗格应具有预定义的宽度(以像素为单位),并且水平滚动条应出现。如果水平滚动条移到右端,则应显示较宽的线的末端。

0 个答案:

没有答案