Python Forum
Not understanding the correlation between code and geometry with Tkninter
Thread Rating:
  • 1 Vote(s) - 1 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Not understanding the correlation between code and geometry with Tkninter
#1
Hello, I recently started working on a personal app to help me learn GUI programming with python Tkinter. What I am having trouble with is coding the geometry, I learned how to make buttons and labels, but when I run my program I have no control over where they will be displayed within the screen. Here is an example program I wrote, It is to become an online shopping app:
from tkinter import *

root = Tk()

BeveragesButton = Button(master = root, bg = "white", fg = "green", text = "Beverages")
Meat_SeafoodButton = Button(master = root, bg = "white", fg = "green", text = "Meat & Seafood")
BakeryButton = Button(master = root, bg = "white", fg = "green", text = "Bakery")
PantryButton = Button(master = root, bg = "white", fg = "green", text = "Pantry")
Snacks_SweetsButton = Button(master = root, bg = "white", fg = "green", text = "Snacks & Sweets")
Dairy_EggsButton = Button(master = root, bg = "white", fg = "green", text = " Dairy & Eggs")
Frozen_Foods = Button(master = root, bg = "white", fg = "green", text = "Frozen Foods")
ButtonsList1 = [BeveragesButton,Meat_SeafoodButton,BakeryButton,PantryButton,Snacks_SweetsButton,Dairy_EggsButton,Frozen_Foods]

listbox = Listbox(root)
listbox.pack(fill = BOTH,expand = 1)

for button in ButtonsList1:
	listbox.insert(END)
	button.pack()

mainloop()
This is a image of the window python produces from the code:

NOTE: I thought I could show you a picture but I guess this forum doesn't support that.

Anyhow, the problem is, when I run the code, the buttons appear in the bottom center under a large white space. I want the buttons lined up from top to bottom on left side of screen. What can I do to fix my geometry problems?
Reply


Messages In This Thread
Not understanding the correlation between code and geometry with Tkninter - by Intelligent_Agent0 - Aug-03-2018, 04:28 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Beginner question re: Tkinter geometry return2sender 3 964 Jun-19-2023, 06:19 PM
Last Post: deanhystad
Question [Tkinter] How to change geometry? Meffy 4 2,889 Jan-31-2021, 10:35 AM
Last Post: Meffy
  [Tkinter] Window geometry appears different on Win and Linux steve_shambles 6 7,127 Nov-29-2019, 12:30 AM
Last Post: steve_shambles
  Grid geometry doesnt work as expected Sigmiami 3 3,801 Oct-25-2018, 04:56 PM
Last Post: The_Raven
  [Tkinter] What is Controller in this code i am not understanding what is it Rishav 2 7,348 Jul-10-2017, 06:36 PM
Last Post: nilamo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020