python - When using a scrolled canvas in Tkinter, columns of contained frame are cut off -


i'm trying make tkinter widget contains number of tables, frames entries filled using .grid method, can switched between pressing buttons. current attempt @ solution uses following code:

from tkinter import *  def dot(root, num):     root.subframe.destroy()     root.subframe = tframe(root, num)  root = tk()  vscrollbar = scrollbar(root,orient='vertical') vscrollbar.grid(row=1,column=2,sticky=n+e+w+s)  root.defaultframe = mainframe(root) root.canvas = canvas(root, yscrollcommand=vscrollbar.set) root.subframe = frame(root.canvas) vscrollbar.config(command=root.canvas.yview) root.canvas.grid(row=1,column=0) root.subframe.grid(row=0,column=0) 

where mainframe has following structure:

class mainframe(frame):     def __init__(self, root):         frame.__init__(self, root)         self.grid(row=0,column=0)         b1 = button(self, text='table 1', command=lambda: dot(root, 0))         b2 = button(self, text='table 2', command=lambda: dot(root, 1))         b1.grid(row=0, column=0, sticky=n+e+w+s)         b2.grid(row=0, column=1, sticky=n+e+w+s) 

and tframe:

class tframe(frame):     def __init__(self, foor, num):         frame.__init__(self, root.canvas)         in range(12):             self.grid_columnconfigure(i, minsize=50)         x in range(12):             y in range(20):                 label = label(self, text=num)                 label.grid(row=y,column=x,sticky=n+e+w+s)         root.canvas.create_window((0,0),window=self,anchor='nw')         root.canvas.configure(scrollregion=root.canvas.bbox('all')) 

when run code, pressing buttons loads tables, scroll in vertical expected. first 8 columns or visible, no matter how window resized. changing width of mainframe adding empty labels , not affect size of tframe created, if several times wider 8 columns tframe ends being. while have tolerable solution adding horizontal scroll bar vertical, experiences far scrolling in tkinter in general have been negative enough hope avoid using possible means.

okay, found solution. turns out there weren't columns being cut off, whole canvas being cut off, , test cases happened have right number of columns vs column width looked columns after first 8 being cut off.

changing:

root.canvas.grid(row=1,column=0) 

to

root.canvas.grid(row=1,column=0,sticky=n+e+w+s) 

fixed problem.


Comments

Popular posts from this blog

php - Submit Form Data without Reloading page -

linux - Rails running on virtual machine in Windows -

php - $params->set Array between square bracket -