Advertisement
Guest User

Untitled

a guest
Aug 22nd, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. def onChange(self, test):
  2. print('Content is: ', test.widget.get())
  3. #this also works, but only when having "test" or any other other second parameter name in the def line:
  4. print('Content is: ', self.var.get())
  5.  
  6. def onChange(self):
  7. print('Content is: ', self.var.get())
  8.  
  9. import tkinter as tk
  10. from tkinter import ttk
  11.  
  12. class GUI:
  13. def __init__(self):
  14. self.window = tk.Tk()
  15. self.create_widgets()
  16.  
  17. # The following function works with "test" or any other second parameter name in the def line:
  18. def onChange(self, test):
  19. print('Content is: ', test.widget.get())
  20. #this also works, but only when having "test" or any other other second parameter name in the def line:
  21. print('Content is: ', self.var.get())
  22.  
  23. ## The following function does not works with "test" or any other second parameter name in the def line:
  24. # def onChange(self):
  25. # print('Content is: ', self.var.get())
  26.  
  27.  
  28. def create_widgets(self):
  29. # Makes an Entry widget:
  30. self.string_entry = ttk.Entry(self.window,width=30)
  31. self.string_entry.grid(row=0,column=0)
  32.  
  33. self.var = tk.StringVar()
  34. self.var.set('Change me and press enter!')
  35.  
  36. self.string_entry["textvariable"]=self.var
  37. self.string_entry.bind('<Key-Return>', self.onChange)
  38.  
  39. program = GUI()
  40. program.window.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement