In python using Tkinter, there are two types of Input Box first is Tkinter Entry Box and Second is Tkinter Text. And if you want to get String or Get Value from Entry in Tkinter or Get Tkinter Text Value in Python then here you will find detailed process to consider how to use it in your Project.
How to use Tkinter Label in Python with features
Now Let’s Learn How to Get Value from Entry in Python Tkinter or Get Value from Text with following way:
So, Let’s Start.
Python Code:
One more thing here you can use get value in Label through following two way:
or
You can use it according to your desire. Both will present same result.
Output:
You can also Set Tkinter window in Center Location.
In Text Widget you have to pass Index inside Get() function:
Code:
Now, when you run you code, this will present following output.
Different types of Multi Line String process in Python
Output:
So, these above given code process is use to Get Tkinter Text Value in Label or Get Entry Value in Python.
How to use Tkinter Label in Python with features
Important Note: We Find that Text widget can not work in Tab Order. You have to write more code effort to perform Tab order in Text in Tkinter. But if you use Entry widget in python. There will no problem in tab order.
Now Let’s Learn How to Get Value from Entry in Python Tkinter or Get Value from Text with following way:
- Get Entry Value in Label in Python Tkinter
- Get Text Value in Label in Python Tkinter
So, Let’s Start.
(1). Get Entry Value in Label in Python Tkinter :
As you know that for perform any action in Python you have to define Function. So for getting value you have to define function as bellow and Get Entry Value.Python Code:
from tkinter import * MyRootDialog=Tk() #Set Tkinter Size And Location MyRootDialog.geometry("200x150+100+100") #Set Tkinter Title MyRootDialog.title("Get Input Value in Label") # Define Function for get Value def Get_MyInputValue(): getresult = MyEntryBox.get() myTKlabel['text'] = getresult # Create Tkinter Entry Widget MyEntryBox = Entry(MyRootDialog, width=20) MyEntryBox.place(x=5, y=6) myTKlabel = Label(MyRootDialog, borderwidth=1, relief="ridge", height=3, width=25) myTKlabel.place(x=4, y=42) #command will call the defined function MyTkButton = Button(MyRootDialog, height=1, width=10, text="Get text", command= Get_MyInputValue) MyTkButton.place(x=4, y=112) mainloop()
One more thing here you can use get value in Label through following two way:
myTKlabel['text'] = getresult
or
myTKlabel.config(text = getresult)
You can use it according to your desire. Both will present same result.
Output:
You can also Set Tkinter window in Center Location.
(2). Get Text Value in Label in Python Tkinter :
Now if you use Tkinter Text widget in python then you have to write following code to get Tkinter text in python.
Note: Get Value from Tkinter Entry Widget code: MyEntryBox.get()
And for get Value from Tkinter Text Widget code: MyTktextBox.get("1.0", 'end-1c')
And for get Value from Tkinter Text Widget code: MyTktextBox.get("1.0", 'end-1c')
In Text Widget you have to pass Index inside Get() function:
from tkinter import * MyRootDialog=Tk() #Set Tkinter Size And Location MyRootDialog.geometry("200x150+100+100") #Set Tkinter Title MyRootDialog.title("Get Input Value in Label") # Define Function for get Text Value def Get_TKTextValue(): myTxtresult = MyTktextBox.get("1.0", 'end-1c') myTKlabel.config(text = myTxtresult) # Create Tkinter Text Widget MyTktextBox=Text(MyRootDialog, height=1, width=20) MyTktextBox.place(x=5, y=6) myTKlabel = Label(MyRootDialog, borderwidth=1, relief="ridge", height=2, width=25) myTKlabel.place(x=4, y=42) #command will call the defined function MyButton = Button(MyRootDialog, height=1, width=10, text="Get text", command= Get_TKTextValue) MyButton.place(x=4, y=92) mainloop()
Now, when you run you code, this will present following output.
Different types of Multi Line String process in Python
Output:
So, these above given code process is use to Get Tkinter Text Value in Label or Get Entry Value in Python.
AttributeError: 'NoneType' object has no attribute 'get'
ReplyDeletefrom tkinter import *
def Get():
getresult = EntryField.get()
print(getresult)
root = Tk()
EntryField = Entry(root).pack()
OutTxt = Label(root, text = "Ergebnis").pack()
CalcBtn = Button(root, text = "Berechnen", command = Get).pack()
root.mainloop()
You have to extract you coding line:
DeleteEntryField = Entry(root).pack()
with
EntryField = Entry(root)
EntryField.pack()
After that you will get desire result without error.