(May-18-2023, 03:22 PM)deanhystad Wrote: If you are going to write a class, why not subclass Tk()?
# Do not use wildcard imports. They fill the global namespace with names, # many of which you might be unaware. import tkinter as tk # Convention is to use Pascal case for class names. This would be Gui, not GUI. # Following conventions makes it easier for others to read your code. class GUI(tk.Tk): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) # Normally you want the contents to set the window size # instead of using geometry. self.geometry=("800x280") self.resizable(width=False, height=False) # Don't need to remember the button. No need to assign to a variable. tk.Button( self, text = "Generate Password", command=self.DoSomething ).grid(row=8, column=0, padx=5, pady=5) # Cannot daisychain creating the Entry and setting the grid location. # .grid() returns None, so x = tk.Entry().grid() sets x = None. # For an Entry you should consider using a StringVar. Provides # a cleaner interface for getting or setting the text. self.gen_pass_text = tk.StringVar(self, "") tk.Entry( self, textvariable = self.gen_pass_text, width=80, bd=3, font=('Bold') ).grid(row=8, column=1, padx=5, pady=5) # Convention is to use snake_case for attributes (including methods). # This would be do_someting or dosomething. genPassText would be # gen_pass_test. def DoSomething(self): """Should have a docstring that describes what it does.""" text = self.get_pass_text.get() text = "".join(reversed(text)) self.get_pass_text.set(text) if __name__ == '__main__': mainwindow = GUI() mainwindow.mainloop()
Double thank you for the additional information . Your answer is not only helpful but really helps people.