Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def onChange(self, test):
- print('Content is: ', test.widget.get())
- #this also works, but only when having "test" or any other other second parameter name in the def line:
- print('Content is: ', self.var.get())
- def onChange(self):
- print('Content is: ', self.var.get())
- import tkinter as tk
- from tkinter import ttk
- class GUI:
- def __init__(self):
- self.window = tk.Tk()
- self.create_widgets()
- # The following function works with "test" or any other second parameter name in the def line:
- def onChange(self, test):
- print('Content is: ', test.widget.get())
- #this also works, but only when having "test" or any other other second parameter name in the def line:
- print('Content is: ', self.var.get())
- ## The following function does not works with "test" or any other second parameter name in the def line:
- # def onChange(self):
- # print('Content is: ', self.var.get())
- def create_widgets(self):
- # Makes an Entry widget:
- self.string_entry = ttk.Entry(self.window,width=30)
- self.string_entry.grid(row=0,column=0)
- self.var = tk.StringVar()
- self.var.set('Change me and press enter!')
- self.string_entry["textvariable"]=self.var
- self.string_entry.bind('<Key-Return>', self.onChange)
- program = GUI()
- program.window.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement