0

What i wanted to do is, while typing some words in Entry widget, at the same time changing the characters that are displayed in label widget. Here are the codes:

import tkinter as tk


class App(tk.Frame):
    def __init__(self, master=None):
        tk.Frame.__init__(self, master)

        self.entry = tk.Entry(master=self)
        self.entry.pack(side="left")

        self.var = tk.StringVar()
        self.var.set(self.entry.get)

        self.label = tk.Label(master=self)
        self.label.pack(side="left")

        self.configure_widgets()
        self.pack()

    def configure_widgets(self):
        self.label.configure(textvariable=self.var)


if __name__ == "__main__":
    root = tk.Tk()
    example = App(master=root)
    example.mainloop()

Which parts i should change of the codes? Thank you in advance.

2
  • You want to display the same text in the Entry and the Label? Commented Jul 10, 2017 at 20:16
  • Yes, the problem was solved by FamousJameous' message, thank you. Commented Jul 10, 2017 at 20:18

1 Answer 1

1

Both Entry and Label accept a variable as a parameter. The entry will set the variable value and the Label will get it.

import tkinter as tk


class App(tk.Frame):
    def __init__(self, master=None):
        tk.Frame.__init__(self, master)

        self.var = tk.StringVar()

        self.entry = tk.Entry(master=self, textvariable=self.var)
        self.entry.pack(side="left")

        self.label = tk.Label(master=self, textvariable=self.var)
        self.label.pack(side="left")

        self.configure_widgets()
        self.pack()

    def configure_widgets(self):
        self.label.configure(textvariable=self.var)


if __name__ == "__main__":
    root = tk.Tk()
    example = App(master=root)
    example.mainloop()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.