水平滚动条在 Tkinter 中不能以 table 的形式工作

Horizontal scrollbar doesn´t work in a kind of table in Tkinter

我正在尝试使用 tkinter 为 python 创建一个 table:

我有下一个代码:

from tkinter import *
from  tkinter import ttk

ws  = Tk()
ws.title('PythonGuides')
ws.geometry('500x500')
ws['bg'] = 'Black'

game_frame = Frame(ws)
game_frame.pack()

game_scroll = Scrollbar(game_frame, orient='vertical')
game_scroll.pack(side=RIGHT, fill=Y)

game_scroll = Scrollbar(game_frame,orient='horizontal')
game_scroll.pack(side= BOTTOM,fill=X)

my_game = ttk.Treeview(game_frame,yscrollcommand=game_scroll.set, xscrollcommand =game_scroll.set)

my_game.pack()

game_scroll.config(command=my_game.yview)
game_scroll.config(command=my_game.xview)

my_game['columns'] = ('_id', '_name')

my_game.column("#0", width=0,  stretch=NO)
my_game.column("_id",anchor=CENTER, width=80)
my_game.column("_name",anchor=CENTER,width=80)

my_game.heading("#0",text="",anchor=CENTER)
my_game.heading("_id",text="Id",anchor=CENTER)
my_game.heading("_name",text="Step",anchor=CENTER)

#add data 
for i in range(40):
    my_game.insert(parent='',index='end',iid=i,text='',values=(str(i + 1),'Going to the step '+str(i + 1)))
my_game.pack()
ws.mainloop()

主要问题是水平滚动条不起作用,所以我看不到它在哪一步。

只是看起来像这样:

我只能向下或向上移动,但不能向左或向右移动。 所以我希望有人能帮助我,在此先感谢。

您有同名的垂直和水平滚动条。 尝试按照以下代码片段更改代码。

game_scrollV = Scrollbar(game_frame, orient='vertical')
game_scrollV.pack(side=RIGHT, fill=Y)

game_scrollH = Scrollbar(game_frame,orient='horizontal')
game_scrollH.pack(side= BOTTOM,fill=X)

my_game = ttk.Treeview(
    game_frame,
    yscrollcommand = game_scrollV.set,
    xscrollcommand = game_scrollH.set)

my_game.pack()

game_scrollV.config(command=my_game.yview)
game_scrollH.config(command=my_game.xview)

my_game.column("_id",anchor=CENTER, minwidth = 100, width=80)
my_game.column("_name",anchor=CENTER,minwidth = 100, width=80)