Apr-14-2020, 03:28 PM
I been following the tutorial here on grids making my own little project and have ran into a snag.
I have a menu of button across the top and can't seem to get all buttons correct with and sizing.
I am posting all code but will point out problem area. Any help with what I'm doing wrong would be great. Thanks
Sorry. I should have posted in the GUI section.
I got it to work using this in the parent
I have a menu of button across the top and can't seem to get all buttons correct with and sizing.
I am posting all code but will point out problem area. Any help with what I'm doing wrong would be great. Thanks
#! /usr/bin/env python3.8 import tkinter as tk from tkinter import ttk from PIL import Image, ImageTk import string class MainWindow: def __init__(self, master): self.master = master self.main_frame_style = ttk.Style() self.main_frame_style.configure('MainFrame.TFrame', background = 'slategray') self.main_frame = ttk.Frame(self.master, style = 'MainFrame.TFrame') self.main_frame.grid(column = 0, row = 0, sticky = ('n','s','e','w')) # self.main_frame.grid_columnconfigure(1, weight = 1, uniform = 'john') self.header_style = ttk.Style() self.header_style.configure('Header.TLabel', background = 'slategray3', relief = 'groove', anchor = 'center', padding = (2,2,2,2)) load = Image.open('/home/johnny/Desktop/cookbook_logo.png') render = ImageTk.PhotoImage(load) self.header = ttk.Label(self.main_frame, image = render, style = 'Header.TLabel') self.header.grid(column = 0, row = 0, columnspan = 26, ipadx = 10, ipady = 5, sticky = ('n','s','e','w')) self.header_img = render ############## For the button menu ############################### # Make letter menu self.button_style = ttk.Style() self.button_style.configure('MY_Button.TButton', width = 3, padding = (2,2,2,2), background = 'skyblue') ## <------ I can set width to 8 and all buttons are even but it expand to the whole window. I'm wanting it to do that only when window is resized letters = string.ascii_uppercase i=0 for letter in letters: self.button = ttk.Button(self.main_frame, text = letter, style = 'MY_Button.TButton') self.button.grid(column = i, row = 1, sticky = ('n','s','e','w')) i += 1 ########################################################################################### self.left_label_style = ttk.Style() self.left_label_style.configure('Left.TLabel', background = 'slategray3', relief = 'groove', padding = (8,8,8,8)) self.left_label = ttk.Label(self.main_frame, text = 'Just some text on the left', style = 'Left.TLabel') self.left_label.grid(columnspan = 8, column = 0, row = 2, sticky = ('n','s','e','w')) self.right_label_style = ttk.Style() self.right_label_style.configure('Right.TLabel', background = 'slategray3', relief = 'groove', padding = (8,8,8,8)) self.right_label = ttk.Label(self.main_frame, text = 'Just some text on the right', style = 'Right.TLabel') self.right_label.grid(columnspan = 18, column = 8, row = 2, sticky = ('n','s','e','w')) # Resize config self.master.columnconfigure(0, weight = 1) self.master.rowconfigure(0, weight = 1) self.main_frame.columnconfigure(0, weight = 3) self.left_label.columnconfigure(0, weight = 3) self.right_label.columnconfigure(0, weight = 3) self.button.rowconfigure(1, weight = 3) # I've even did a loop here to cover all columns and still no success def main(): root = tk.Tk() root.title("Johnny's CookBook") root.configure(borderwidth = 5, highlightcolor = 'slategray', highlightbackground = 'slategray', highlightthickness = 4) window = MainWindow(root) root.mainloop() if __name__ == '__main__': main()
Sorry. I should have posted in the GUI section.
I got it to work using this in the parent
for i in range(26): self.main_frame.grid_columnconfigure(i, weight = 3, uniform = 'john')