Saurabh G
Saurabh G

Reputation: 19

I am not getting the output printed on python idle using tkinter

from tkinter import *

here i am printing the data given by user in the def save_info section, my GUI is working. but after pressing submit button, data is not displayed on the promt screen.

#Printing input data
def save_info():
    email_info = email.get()
    name_info  = name.get()
    mobileno_info = mobileno.get()
    print(email_info, name_info, mobileno_info)

# Making Screen
screen = Tk()
screen.geometry( "800x800" )
screen.title( "Assignment" )
heading = Label( text="Tkinter", bg="red", width="600", height="2" )
heading.pack()

# Input From User
email_text   = Label(text="Email :")
name_text    = Label(text= "Name :")
mobno_text  = Label(text="Mobile Number :")
email_text.place(x=15, y=70)
name_text.place(x=15, y=140)
mobno_text.place(x=15, y=210)

# Entry Fields
email = StringVar()
name  = StringVar()
mobileno = IntVar()

email_input = Entry(textvariable = email, width="40")
name_input  = Entry(textvariable = name,width="40")
mobileno_input = Entry(textvariable = mobileno, width="40")

#Entry Place
email_input.place(x=15, y=100)
name_input.place(x=15, y=170)
mobileno_input.place(x=15, y=240)

# Submit Button
submit = Button(text="Submit", width="33", height="2", bg="grey")
submit.place(x=15,y=280)

Upvotes: 0

Views: 258

Answers (1)

Mike - SMT
Mike - SMT

Reputation: 15226

Your button is missing a command.

Change:

submit = Button(text="Submit", width="33", height="2", bg="grey")

To:

submit = Button(text="Submit", width="33", height="2", bg="grey", command=save_info)

That said you should change a couple things.

  1. Do not use import * this can cause you to overwrite imports and other methods. Use import tkinter as tk instead and then use the tk. prefix for your widgets and other tkinter code.

  2. Do not use place() for general widget placement. pack() and grid() are typically what you want to use and they are easier to maintain. The place() manager has its uses but there is nothing here that should be using it.

Upvotes: 1

Related Questions