Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python Tkinter Grid Manager and Entry Widget

Tags:

python

tkinter

This is my code so far:

master = Tk()
Label(master, text="Input:").grid(row=0)

e1 = Entry(master, width = 100)
e1.grid(row=0, column=1)

Button(master, text='Q', command=q_pressed).grid(row=3, column=2,
                                                sticky=W, padx = 4, pady=4)

Button(master, text='C', command =c_input).grid(row=3, column=1,
                                                sticky=W, padx = 0, pady=4)

Button(master, text='Confirm', command=parse_input).grid(row=3, column=0,
                                                sticky=W, padx = 4, pady=4)

I am trying to make it so that "Q" button is next to the "C" button (like how "C" is next to the "Confirm" button) but it instead places it where the Entry widget ends.

I understand this is a grid management issue. How do I set up a layout so row = 0, has text and entry widget and row=3 has its own independent columns (0,1,2) for the buttons?

like image 518
user1077071 Avatar asked Sep 22 '26 08:09

user1077071


1 Answers

Your problem is that the Entry e1 is very long and contains 100 characters, but it spans only one column. You can use columnspan to define the number of used columns for e1 in the grid command. Following example with columnspan = 30 works for me. Decide yourself, what would be a reasonable value for columnspan.

from Tkinter import *
master = Tk()
Label(master, text="Input:").grid(row=0)

e1 = Entry(master, width = 100)
e1.grid(row=0, column=1, columnspan=30)

Button(master, text='Q').grid(row=3, column=2)

Button(master, text='C').grid(row=3, column=1)

Button(master, text='Confirm').grid(row=3, column=0)
mainloop()
like image 183
Holger Avatar answered Sep 24 '26 22:09

Holger