By ath0rus


2020-02-14 08:49:40 8 Comments

I am trying to design a GUI for a bit of fun. the purpose of the code is to take what you entered into a "entry widget" and print it out in the terminal using the print() command when you press the submit button.

Two questions.

One: i keep getting an "Invalid syntax" error in the code both the root.geometry() and root.mainloop()

root.geometry("300x300")

root.mainloop()

two: is there a more effective way of getting the text from a tkinter entry widget and storing it in a variable. i would like to be able to store data from multiple entry widgets to multiple variables, and how can i do that.

Here is my full code.

from tkinter import *

root = Tk()

def get_input():
    val = e1.get("1.0", "end-1-c")
    print(val)

lbl1 = Label(root, text = "Enter your name:").grid(row= "0", column= "0")
e1 = Entry(root, borderwidth = 5, width = 20).grid(row = "0", column = "1")
sbut = Button(root, text = "submit", command = get_input.grid(row= "1", column = "0")

root.geometry("300x300")

root.mainloop()

i used https://www.youtube.com/watch?v=FueIPFqRyyY&t=85s for the code to save entry widget data to a varible

Thanks for any help 😊

1 comments

@phoenixo 2020-02-14 08:57:17

You should not define a widget and .grid() it in the same line. You also had an Invalid syntax because you forgot a ) at the line sbut = Button(....grid(row= "1", column = "0"))

You can try this :

from tkinter import *

root = Tk()

def get_input():
    val = e1.get()
    e1.delete("0", "end")
    print(val)

lbl1 = Label(root, text = "Enter your name:")
lbl1.grid(row= "0", column= "0")
e1 = Entry(root, borderwidth = 5, width = 20)
e1.grid(row = "0", column = "1")
sbut = Button(root, text = "submit", command = get_input)
sbut.grid(row= "1", column = "0")

root.geometry("300x300")

root.mainloop()

@ath0rus 2020-02-14 09:19:27

Thanks for your Help phoenixo. i will use your advice.

@phoenixo 2020-02-14 09:33:41

another advice for you : it is not advised to use from tkinter import *, you'd better use import tkinter as tk and then use root = tk.Tk(), e1 = tk.Entry() ...

Related Questions

Sponsored Content

2 Answered Questions

[SOLVED] finding widgets on a grid (tkinter module)

4 Answered Questions

[SOLVED] Python timer in math game Tkinter

2 Answered Questions

[SOLVED] ttk tkinter multiple frames/windows

1 Answered Questions

[SOLVED] Tkinter: how to clear Entry Widget and copy multiple notes to a CSV file

3 Answered Questions

[SOLVED] Python Tkinter Grid Manager and Entry Widget

  • 2013-01-01 21:16:34
  • user1077071
  • 15297 View
  • 3 Score
  • 3 Answer
  • Tags:   python tkinter

1 Answered Questions

updating a text widget with text from entry widgets - python

  • 2014-03-12 07:04:35
  • user3409330
  • 409 View
  • 0 Score
  • 1 Answer
  • Tags:   python tkinter

2 Answered Questions

How to effectively line up tkinter widgets

  • 2013-10-14 17:49:19
  • Jerry
  • 1108 View
  • 0 Score
  • 2 Answer
  • Tags:   python tkinter

3 Answered Questions

Tkinter - text widget distorting column sizes

  • 2012-07-13 05:25:36
  • SQLesion
  • 1545 View
  • 0 Score
  • 3 Answer
  • Tags:   python tkinter

Sponsored Content