CustomTkinter icon indicating copy to clipboard operation
CustomTkinter copied to clipboard

NameError: name 'app' is not defined

Open sim2511 opened this issue 2 years ago • 1 comments

Hello,

I separate my GUI from my main code in 2 files main.py and interface.py (the customtkinter GUI inside)

When I run get_action function (which is inside my main.py)I have the following error <<NameError: name 'app' is not defined>> (which means app is not global in my if name == "main": ? how can I correct this please? :

here my main.py code: from interface import * if name == "main": app = App() app.mainloop() print(app.optionmenu_type_chaine.get())#send me the correct information when program close

def get_action(): print(app.optionmenu_type_chaine.get())

sim2511 avatar Jan 14 '23 23:01 sim2511

my interface.py :

import customtkinter from main import *

class App(customtkinter.CTk): def init(self): super().init() self.geometry("300x150")#taille de la fenetre graphique self.optionmenu_type_chaine = customtkinter.CTkOptionMenu(master=self, values=["", "Daily", "Weekly", "Monthly"], width=200, height=30, fg_color=("white", "gray38"),text_font=("Roboto Medium", -16)) self.optionmenu_type_chaine.grid(row=2, column=1, padx=5, pady=5) self.button_recup_action = customtkinter.CTkButton(master=self,text="Cliquer ici",command=get_action, width= 200) self.button_recup_action.grid(row=6, column=1, pady=5, padx=5)

app = App()

sim2511 avatar Jan 15 '23 01:01 sim2511