我正在用python3/tkinter编写一个小GUI。我要做的是生成一个包含数据表(如电子表格)的窗口,并使该表可以水平和垂直滚动。现在我只想显示数据,所以我使用了一个标签网格。数据显示工作正常,但我无法让滚动条正常工作。下面是我的代码的相关部分;它所在的类继承自tk.Toplevelframe = self.frame = tk.Frame(self)
self.frame.grid(row=1, columnspan=2, padx=2, pady=2, sticky=tk.N+tk.E+tk.S+tk.W)
self.text_area = tk.Canvas(self.frame, background="black", width=400, height=500, scrollregion=(0,0,1200,800))
self.hscroll = tk.Scrollbar(self.frame, orient=tk.HORIZONTAL, command=self.text_area.xview)
self.vscroll = tk.Scrollbar(self.frame, orient=tk.VERTICAL, command=self.text_area.yview)
self.text_area['xscrollcommand'] = self.hscroll.set
self.text_area['yscrollcommand'] = self.vscroll.set
self.text_area.grid(row=0, column=0, sticky=tk.N+tk.S+tk.E+tk.W)
self.hscroll.grid(row=1,