Tkinter Treeview小部件,滚动条问题

问题描述 投票:0回答:1

我正在尝试添加一个与玩家的姓名,位置,身高,体重和大学同步的滚动条,但我只能在玩家表(treeview)中滚动。] >>

有人可以帮助我,并向我提供滚动条问题的代码吗?

这里是代码:

from tkinter import *
from tkinter import ttk

root = Tk()
root.geometry("850x500")

none = []

player = open('NBA n ABA players.txt', 'r', encoding='utf-8')
content = player.readlines()
players = [s.strip('\n') for s in content]


pos = open('pos.txt', 'r', encoding='utf-8')
content2 = pos.readlines()
positions = [s.strip('\n') for s in content2]

ht = open('ht.txt', 'r', encoding='utf-8')
content3 = ht.readlines()
hts = [s.strip('\n') for s in content3]

wt = open('wt.txt', 'r', encoding='utf-8')
content4 = wt.readlines()
wts = [s.strip('\n') for s in content4]

college = open('colleges.txt', 'r', encoding='utf-8')
content5 = college.readlines()
colleges = [s.strip('\n') for s in content5]

frame = Frame(root)
frame.pack()

tree = ttk.Treeview(frame, columns=1, height=len(players), show="headings")
tree_pos = ttk.Treeview(frame, columns=1, height=len(positions), show="headings")
tree_ht = ttk.Treeview(frame, columns=1, height=len(hts), show="headings")
tree_wt = ttk.Treeview(frame, columns=1, height=len(wts), show="headings")
tree_col = ttk.Treeview(frame, columns=1, height=len(colleges), show="headings")

tree.pack(side='left')
tree_pos.pack(side='left')
tree_ht.pack(side='left')
tree_wt.pack(side='left')
tree_col.pack(side='left')

tree.heading(1, text="NBA / ABA PLAYERS")
tree_pos.heading(1, text="Position")
tree_ht.heading(1, text="Height")
tree_wt.heading(1, text="Weight")
tree_col.heading(1, text="Colleges")


tree.column(1, width=140)
tree_pos.column(1, width=140)
tree_ht.column(1, width=140)
tree_wt.column(1, width=140)
tree_col.column(1, width=240)

scroll = ttk.Scrollbar(frame, orient="vertical")
scroll.pack(side='right', fill='y')

for x in players:
        tree.insert('', 'end', values=[x])

for x in positions:
        tree_pos.insert('', 'end', values=[x])

for x in hts:
        tree_ht.insert('', 'end', values=[x])

for x in wts:
        tree_wt.insert('', 'end', values=[x])

for x in colleges:
        tree_col.insert('', 'end', values=[x])


root.mainloop()

输出窗口的屏幕快照的链接:https://i.stack.imgur.com/kXYMv.png

我正在尝试添加一个与玩家的姓名,位置,身高,体重和大学同步的滚动条,但我只能滚动浏览玩家表(树状视图)。有人可以帮我吗...

python-3.x tkinter treeview
1个回答
0
投票

我认为您应该将QtDesigner用于QTPython。它非常易于使用。就像Tkinter GUI一样,但区别在于它允许拖放GUI。

© www.soinside.com 2019 - 2024. All rights reserved.