-1

I want to read out an input from an input field in a GUI. My Problem is that my Code don't work if I use the grid() method for the order. If I use the pack() method it works... What I have to do, that the get() method also works in combination with the grid() method?

e.g. for work with pack()

from tkinter import *  

def function1():
    ci = e1.get()
    print(c1)

window = Tk()

e1 = Entry(window)
b1 = Button(text="Ok", command=read_input_field)

e1.pack()
b1.pack()

window.mainloop()

e.g. for doesn't work with grid()

from tkinter import *  

def function1():
    ci = e1.get()
    print(c1)

window = Tk()

e1 = Entry(window).grid(row=1, column=2)
b1 = Button(text="Ok", command=read_input_field).grid(row=1, column=2) 

window.mainloop()

I hope you can help me.

A warm thank you in advance

tron

tron
  • 1

1 Answers1

0

The PROBLEM is that the .grid method returns nothing, so b1 has the wrong value. You need to do that as two separate lines:

b1 = Button(text="Ok", command=read_input_field)
b1.grid(row=1, column=2)

tkinter was designed more than a generation ago. It is not object-oriented in any way.

Tim Roberts
  • 48,973
  • 4
  • 21
  • 30