Jul-13-2020, 12:53 AM
I've worked on this awhile and can't seem to get it align right and the scrollbar to work at the same time. Widths are right if you uncomment the scrollframe grid. But the scrollbar doesn't work. Maybe you can find a work around.
#! /usr/bin/env python3 import tkinter as tk from tkinter import ttk class MyClass: def __init__(self, parent): self.parent = parent self.parent.columnconfigure(0, weight=1) self.parent.rowconfigure(0, weight=1) self.mainframe = tk.Frame(self.parent) self.mainframe.grid(column=0, row=0, sticky='new') self.mainframe.grid_columnconfigure(0, weight=3) self.headerframe = tk.Frame(self.mainframe) self.headerframe.grid(column=0, row=0, sticky='ew') for i in range(0, 8): self.headerframe.grid_columnconfigure(i, weight=3, uniform='header') self.contentframe = tk.Frame(self.mainframe, bg='green') self.contentframe.grid(column=0, row=1, sticky='new') self.contentframe['relief'] = 'solid' self.contentframe['borderwidth'] = 1 self.contentframe['highlightbackground'] = 'grey65' self.contentframe['highlightthickness'] = 1 self.contentframe.grid_columnconfigure(0, weight=3) canvas = tk.Canvas(self.contentframe, bg='pink') scrollbar = ttk.Scrollbar(self.contentframe, orient='vertical', command=canvas.yview) self.scrollframe = tk.Frame(canvas) self.scrollframe.bind( '<Configure>', lambda event: canvas.configure(scrollregion=canvas.bbox('all')) ) canvas.create_window((0, 0), window=self.scrollframe) canvas.configure(yscrollcommand=scrollbar.set) # You can comment this out and the scroll fame will work but, it shrinks self.scrollframe.grid(column=0, row=0, sticky='news') for i in range(0, 8): self.scrollframe.grid_columnconfigure(i, weight=3, uniform='test') scrollbar.grid(column=1, row=0, sticky='ns') canvas.grid(column=0, row=0, sticky='news') canvas.grid_columnconfigure(0, weight=3) self.headers() self.combo_box(40) self.entrybox(1, 20, 5) self.chkbox(3, 30) self.entrybox(6,10, 15) self.chkbox(7, 10) def headers(self): headers = ["Field Name","Field Label","Default Value","ReadOnly","Copy","Mandatory","Sort Order","Remove"] col = 0 for header in headers: label = tk.Label(self.headerframe) label['text'] = header label['relief'] = 'solid' label['borderwidth'] = 1 label['highlightbackground'] = 'grey65' label['highlightthickness'] = 1 label.grid(column = col, row=0, sticky='ew') col += 1 def combo_box(self, howmany): for i in range(0, howmany): combobox = ttk.Combobox(self.scrollframe) combobox.grid(column=0, row=i, sticky='new', padx=1) def entrybox(self, col, howmany, padx): row = 0 col = col for i in range(0, howmany): entry = tk.Entry(self.scrollframe) entry.grid(column=col, row=row, sticky='new', padx=padx) if row >= 9: row = 0 col += 1 else: row += 1 def chkbox(self, col, howmany): row = 0 col = col for i in range(0, howmany): box = tk.Checkbutton(self.scrollframe) box.grid(column=col, row=row) if row >= 9: row = 0 col += 1 else: row += 1 def main(): root = tk.Tk() root['padx'] = 10 root['pady'] = 5 root['relief'] = 'ridge' root['borderwidth'] = 5 MyClass(root) root.mainloop() if __name__ =='__main__': main()
I welcome all feedback.
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags