Skip to content Skip to sidebar Skip to footer

How To Pass A Textbox Entry To Variables Using Tkinter In Python

I have some fairly simple code to get values for a urlstring. I have looked at all the other questions and cant seem to find a relevant answer I can apply Some of the code comes up

Solution 1:

Your problem seems to be you're using cur1_1 and cur2_1 as if they were strings when you should be calling their StringVar.get() methods to access their string values.

A simple-minded example:

import tkinter as tk

def show_text():
    label_text.set('Heh, heh, heh, you said, "' + entry_text.get() + '"')

root = tk.Tk()

entry_text = tk.StringVar()
entry = tk.Entry(root, width=10, textvariable=entry_text)
entry.pack()

button = tk.Button(root, text="Click Me", command=show_text)
button.pack()

label_text = tk.StringVar()
label = tk.Label(root, textvariable=label_text)
label.pack()

root.mainloop()

Put text in the entry box, and click the button. The text will be transfered from the entry box to the label via the .get() method of the StringVar associated with the Entry when it was created.


Post a Comment for "How To Pass A Textbox Entry To Variables Using Tkinter In Python"