I have a simple tkinter app. I want to create a pop up window that allows the user to insert its group. After writing and pressing the enter button the value is validated and if acceptable then I would like to save it. The value of group is taken in the save_and_kil function which is "called" when the button is pressed. I am specifying the command to be called in the button arguments so how can I save the value of groups so that i can access it in other_function?
import tkinter as tk
class SomeClass:
def __init__(self, root):
self.root = root
self.root.title("App")
self.root.geometry("600x450")
self.groups = ["1", "2", "3", "4", "5"]
self.top_window()
self.group = "nothing"
def top_window(self):
a = tk.Toplevel()
a.geometry('400x150')
a.title('Credentials Window')
def save_and_kil():
group = txt_entry.get()
if group in self.groups:
a.destroy()
txt_label = tk.Label(a, text="please write your group")
txt_entry = tk.Entry(a)
enter_but = tk.Button(a,
text='Enter',
command=save_and_kil)
txt_label.grid(column=0, row=0)
txt_entry.grid(column=1, row=0)
enter_but.grid(column=1, row=1)
# somehow make redefine the value of self.group
def other_function(self):
print(self.group)
pass
roott = tk.Tk()
app = SomeClass(roott)
roott.mainloop()