1

In python, I am using the tkinter module in order to create a login screen. It is fully functioning with all the widgets in the correct places, but the only problem being is that when I drag the screen out larger, the widget's sizes don't increase in scale with the size of the main window.

from tkinter import *

root = Tk()

f1 = Frame(root)
f1.grid(row=0, column=0, sticky='news')

enter = Frame(f1)

e1 = Entry(enter,font=('Consolas',15),width=25)
e1.insert(0,'E-mail')
e1.pack(pady=10)

e2 = Entry(enter,font=('',15),show='*',width=25)
e2.insert(0,'E-mail')
e2.pack(pady=20)
enter.grid(row=1,column=0,columnspan=3,padx=20,sticky='nsew')

loginframe = Frame(f1)
loginbutton = Button(loginframe,text='Login!',bg='lightblue',height=2,width=39)
loginbutton.pack()
loginframe.grid(row=2,column=0,columnspan=3,sticky='ew')

account = Frame(f1)
Label(account,text="Don't have an account yet?").pack(side=LEFT)
link = Label(account,text="Sign Up!",cursor='hand2',fg='blue',
               font=('Helvetica',8,'underline'))
link.pack(side=BOTTOM)

account.pack()
account.grid(row=3,column=0,columnspan=3)

root.mainloop()
Cœur
  • 37,241
  • 25
  • 195
  • 267
Crawley
  • 600
  • 2
  • 8
  • 15
  • What exactly _isn't_ expanding? – Nae Dec 12 '17 at 19:50
  • `frame.grid(row=0, column=0, sticky='news')` places all four frames to the same exact node. – Nae Dec 12 '17 at 19:51
  • The widgets inside f1. I used frame.grid to place them all and my raise_frame function raises the given frame above the others – Crawley Dec 12 '17 at 19:53
  • 1
    Please improve your question by adding [a Minimal, Complete and Verifiable example](https://stackoverflow.com/help/mcve). As is you're asking an unclear question with incomplete code example. – Nae Dec 12 '17 at 20:36
  • 1
    create minimal **working** example with your problem so we could run it and see problem. – furas Dec 12 '17 at 22:04
  • I think I have made it clearer and easier – Crawley Dec 12 '17 at 22:11
  • I got error because you use `account.pack()` and `account.grid()` - don't mix layout managers. – furas Dec 12 '17 at 22:18
  • add background color in frames to see which one doesn't change size - ie. `f1 = Frame(root , bg='red')` . As default grid doesn't change size but you can add `root.columnconfigure(0, weight=1)` and `root.rowconfigure(0, weight=1)` to change it - and then `f1` will change size but still other widgets inside don't change size. – furas Dec 12 '17 at 22:26
  • Please never post ephemeral content like paste.ofcode.org on Stack Overflow. – Cœur Mar 27 '18 at 03:53

1 Answers1

3

As default columns and rows don't change size but you can use this to change it.

columnconfigure(col_number, weight=1)
rowconfigure(row_number, weight=1)

If you have two rows with different weight then row with bigger weight will resize faster.

I added background color to frames to see which one still doesn't change size.

from tkinter import *

root = Tk()

root.columnconfigure(0, weight=1)
root.rowconfigure(0, weight=1)

f1 = Frame(root, bg='red')
f1.grid(row=0, column=0, sticky='news')

f1.columnconfigure(0 , weight=1)
f1.rowconfigure(1, weight=1)
#f1.rowconfigure(2, weight=1)

enter = Frame(f1, bg='green')
enter.grid(row=1, column=0,columnspan=3,padx=20, sticky='nsew')

loginframe = Frame(f1)
loginframe.grid(row=2,column=0,columnspan=3, sticky='ew')

e1 = Entry(enter,font=('Consolas',15),width=25)
e1.insert(0,'E-mail')
e1.pack(pady=10)

e2 = Entry(enter,font=('',15),show='*',width=25)
e2.insert(0,'E-mail')
e2.pack(pady=20)

loginbutton = Button(loginframe,text='Login!',bg='lightblue',height=2,width=39)
loginbutton.pack()

account = Frame(f1)
account.grid(row=3,column=0,columnspan=3)

Label(account,text="Don't have an account yet?").pack(side=LEFT)
link = Label(account,text="Sign Up!",cursor='hand2',fg='blue',
               font=('Helvetica',8,'underline'))
link.pack(side=BOTTOM)

root.mainloop()

Before resize:

enter image description here

After resize with columnconfigure and rowconfigure :

enter image description here

Without columnconfigure and rowconfigure

enter image description here

j_4321
  • 15,431
  • 3
  • 34
  • 61
furas
  • 134,197
  • 12
  • 106
  • 148
  • Ohh thanks so much, so instead of using `columconfigure` & `rowconfigure`on just `root` I need to use them on `f1` as well – Crawley Dec 12 '17 at 22:34
  • you may have to use on both. I use on both. If you add background color then you see which one doesn't change size. – furas Dec 12 '17 at 22:35