2

When I type a simple hello world gui with a button that does nothing, the tk window doesn't do what I wanted. I want the window to remain 500 x 500 while there's a small button in the top left. Here's my current simple code:

from tkinter import *
window = Tk()
window.config(height = 500, width = 500) #the window initialize as a 500px x 500px window
button = Button(window, text = 'hello world')  
button.pack() #but when I added a button, the window shinks to the size of the button
window.mainloop() 

I'm running Mac Sierra with python 3.6. And downloadeded an external tkl as told by the manual.

Srcreenshot

Lisa Xu
  • 67
  • 3

1 Answers1

1

Heyo, the expand function will fill the remaining areas with empty space. You can set expand to any value as long as it's not 0, and it will do so.

from tkinter import *
window = Tk()
window.config(height = 500, width = 500)
button = Button(window, text = 'hello world')  
button.pack(expand = 1) #Lookie here
window.mainloop()

Good luck to whatever project you're working on. :D

Lunkle
  • 145
  • 1
  • 2
  • 9