1

Using tkinter, I wanted to make an interface containing a few buttons on the left, which would be fairly static and align with the widgets on the right fairly nicely. On the right, I wanted an Entry widget above a Text widget, both of which would resize accordingly (the Entry widget only on the X axis).

This code accomplishes most of that, except the Text widget does not resize and the Entry widget only resizes to align with the Text widget. Upon trying to column/rowconfigure the root, the top frame resizes awkwardly.

Here's a picture of the tkinter interface from this code:

output

from tkinter import *

def main():
    root = Tk()
    root.geometry("300x400")

    framet = Frame(root)
    frameb = Frame(root)

    framet.grid(row=0, column=0, sticky='ew')
    frameb.grid(row=1, column=0, sticky='news')

    button1 = Button(framet, text='one', width=8)
    button1.grid(row=0, column=0)

    button2 = Button(frameb, text='two', width=8)
    button2.grid(row=1, column=0, sticky='n')

    entry1 = Entry(framet)
    entry1.grid(row=0, column=1, sticky='ew')

    text1 = Text(frameb, highlightbackground='black', highlightthickness=1)
    text1.grid(row=1, column=1, sticky='news')

    framet.columnconfigure(1, weight=1)

if __name__ == '__main__':
    main()

As you can see, the Entry and Text widgets do not resize. How could I accomplish this whilst still having the Buttons remain static, and not moving anything (only resizing)?

ShuckleShackle
  • 97
  • 1
  • 2
  • 7

1 Answers1

1

Would this work for you? I changed the lines with # comments, I think, I can't really remember what I did I just tryed to get it working, one problem which I'm not happy with though is the entry widget is not the same height as the button, I guess you could manually set its height but..

from tkinter import *

def main():
    root = Tk()
    root.grid_columnconfigure(1,weight=1) # the text and entry frames column
    root.grid_rowconfigure(0,weight=1) # all frames row

    buttonframe = Frame(root)
    buttonframe.grid(row=0, column=0, sticky="nswe")
    entry_text_frame = Frame(root)
    entry_text_frame.grid(row=0, column=1, sticky="nswe")
    entry_text_frame.grid_columnconfigure(0,weight=1) # the entry and text widgets column
    entry_text_frame.grid_rowconfigure(1,weight=1) # the text widgets row

    button1 = Button(buttonframe, text='one', width=8)
    button1.grid(row=0, column=0, sticky='nswe')
    button2 = Button(buttonframe, text='two', width=8)
    button2.grid(row=1, column=0, sticky='nswe')

    entry1 = Entry(entry_text_frame)
    entry1.grid(row=0, column=0, sticky='nswe')

    text1 = Text(entry_text_frame, highlightbackground='black', highlightthickness=1)
    text1.grid(row=1, column=0, sticky='news')

    root.geometry("300x400")

if __name__ == '__main__':
    main()
ragardner
  • 1,836
  • 5
  • 22
  • 45
  • 3
    This answer would be better if you explained what you did differently. Otherwise we have to read line-by-line to figure out what the significant changes are. Also, it doesn't matter when you call the `geometry` command. – Bryan Oakley Oct 24 '17 at 19:08
  • 1
    @BryanOakley Thanks, your explanations of tkinter on stack have really helped me over the last few months. You're helping a lot of people learn GUI development in Python <3 – ragardner Oct 24 '17 at 19:12
  • 1
    Yes I like to think of Bryan as this all knowing AI that never sleeps. – Mike - SMT Oct 24 '17 at 21:02