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()
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.
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.
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>"
#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()