Python Forum
[TkInter]Simple Python Homework
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[TkInter]Simple Python Homework
#1
Hi, this is my first time on this site and first ever time doing python. So the code might (will) be bad. I am trying to have a entry field where whatever the user types in it will print it out when clicking on the button created but it does not work.

this is my code:

from Tkinter import *

root = Tk()

label = Label(root, text="Name")
label.grid(row=0, column=0)

entry = Entry(root, bd=5)

entry.grid(row=0, column=1)


def helloCallback():
print ()


b = Button(root, text="Submit", command=helloCallback)
b.grid(row=0, column=2)

root.mainloop()
Reply
#2
I'm not familiar with Tk/Tkinter but it is frequently the case with GUI's that the normal I/O channels (stdout, stderr) are not accessible.

Try this:
def helloCallback():
    p = # path to a new file on your computer
    with open(p, "w+") as fp:
       print("some text", file=fp)
The file you specify in 'p' should get the output.

You could also try displaying an alert/error/info dialog Tk/Tkinter box.
Reply
#3
Hi Zaji,

Based on your need, first of all, you should get the word what you typed in the entry box and then you have to print it by clicking the submit button

I have modified your code based on your need.
 

from Tkinter import *
root = Tk()

def helloCallback():
    word=entry.get()
    print(word)
 
label = Label(root, text="Name")
label.grid(row=0, column=0)
 
entry = Entry(root, bd=5)
entry.grid(row=0, column=1)

b = Button(root, text="Submit",command=helloCallback)
b.grid(row=0, column=2)
 
root.mainloop()
Regards,
Rizvi.
Reply
#4
thanks it works, just trying to get into HTML with IIS... This is the code i have but it doesn't seem to work. Is it a code fault?

import cgi
from Tkinter import *

form = cgi.FieldStorage ()

print "Content-type: text/html"
print""
print"<HTML><HEAD></HEAD>"
print"<BODY>"


root = Tk()


def helloCallback():
    word = entry.get()
    print(word)


label = Label(root, text="Name")
label.grid(row=0, column=0)

entry = Entry(root, bd=5)
entry.grid(row=0, column=1)

b = Button(root, text="Submit", command=helloCallback)
b.grid(row=0, column=2)

root.mainloop()

print "</BODY>"
print "</HTML>"
Reply
#5
#I hope this helps
from tkinter import *
from tkinter import ttk
window=Tk()

def clicker():
var=entry1.get()
print(var)
label1=ttk.Label(window,text=var)
label1.grid(row=1,column=0)

#button
button1=ttk.Button(window,text="Click Me",command=clicker)
button1.grid(row=0,column=1)

#entry
entry1=ttk.Entry(window,background="blue",foreground="blue")
entry1.grid(row=0,column=0)

window.mainloop()
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Where can I get loooads of simple homework questions for kids? omar 1 975 Nov-09-2022, 02:33 PM
Last Post: Larz60+
  HELP in python homework makashito 4 3,902 Oct-12-2021, 10:12 AM
Last Post: buran
  CyperSecurity Using Python HomeWork ward1995 1 1,949 Jul-08-2021, 03:55 PM
Last Post: buran
Exclamation urgent , Python homework alm 2 2,288 May-09-2021, 11:19 AM
Last Post: Yoriz
  Homework with python Johnsonmfw 1 1,676 Sep-20-2020, 04:03 AM
Last Post: ndc85430
  Please help. Simple homework Asm0deus314 3 3,363 Feb-02-2020, 07:03 PM
Last Post: michael1789
  Python Homework Help *Urgent GS31 2 2,570 Nov-24-2019, 01:41 PM
Last Post: ichabod801
  Python Homework Question OrcDroid123 1 2,364 Sep-01-2019, 08:44 AM
Last Post: buran
  Python homework / functions sunhyunshine 1 2,443 May-11-2019, 05:37 PM
Last Post: MrTheOne
  python homework help ASAP gk34332 1 2,961 Mar-13-2019, 07:27 PM
Last Post: ichabod801

Forum Jump:

User Panel Messages

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