Nur alleine mit dem Internet (Google) geht gewisses dann doch nicht.
Wie zum Beispiel folgendes.
Code: Alles auswählen
class LogOn(tk.Tk):
def __init__(self,*args,**kwargs):
super().__init__(*args,**kwargs)
self.title("*** LOGON ***")
""" Create the Frame """
logon_frame=tk.Frame(self)
""" Define the Variables """
self.name_var=tk.StringVar(self)
self.pwd_var=tk.StringVar(self)
self.message_view=tk.StringVar(self)
""" Define the Labels """
name_label=tk.Label(logon_frame,text="Username: ",padx=3,pady=3).grid(column=0,row=0,sticky=(tk.W))
pwd_label=tk.Label(logon_frame,text="Password: ",padx=3,pady=3).grid(column=0,row=1,sticky=(tk.W))
msg_label=tk.Label(logon_frame,textvariable=self.message_view).grid(column=0,row=3,columnspan=2,sticky=(tk.W,tk.E))
""" Define the Entry-Fields """
name_entry=ttk.Entry(logon_frame,textvariable=self.name_var).grid(column=1,row=0,sticky=(tk.E))
""" To hide the password => show='*' """
pwd_entry=ttk.Entry(logon_frame,show='*',textvariable=self.pwd_var).grid(column=1,row=1,sticky=(tk.E))
""" Define the Button """
logon_button=tk.Button(logon_frame,text="Logon",command=self.logon_cmd,padx=3,pady=3).grid(column=0,row=2,sticky=(tk.W,tk.E))
name_entry.focus_set()
logon_frame.pack(padx=3,pady=3)
python3 dssn.py
Traceback (most recent call last):
File "dssn.py", line 137, in <module>
appl=LogOn()
File "dssn.py", line 26, in __init__
self.name_entry.focus_set()
AttributeError: 'NoneType' object has no attribute 'focus_set'
Ich habe es auch schon mit name_entry.focus() probiert und nahezu die selbe Fehlermeldung bekommen
AttributeError: 'NoneType' object has no attribute 'focus'
In einer anderen Klasse bekomme ich einen ähnlichen Fehler:
Code: Alles auswählen
class MainView(tk.Tk):
def __init__(self,initusr,*args,**kwargs):
super().__init__(*args,**kwargs)
self.title("*** MAINVIEW ("+initusr+") ***")
""" Create the Frames """
main_frame=tk.Frame(self)
top_frame=tk.Frame(main_frame)
left_frame=tk.Frame(main_frame)
right_frame=tk.Frame(main_frame)
center_frame=tk.Frame(main_frame)
""" ------------------------------- """
""" TOP-FRAME (Database-Connection) """
""" ------------------------------- """
""" Define the Entry-Variables """
self.db_con_var=tk.StringVar(self)
self.db_name_var=tk.StringVar(self)
self.db_status_var=tk.StringVar(self)
self.db_conusr_var=tk.StringVar(self)
self.db_admusr_var=tk.StringVar(self)
self.db_secusr_var=tk.StringVar(self)
""" Define the DB-Connection Lists """
self.db_con_list=[""]
self.db_name_list=[""]
self.db_status_list=[""]
self.db_conusr_list=[""]
self.db_admusr_list=[""]
self.db_secusr_list=[""]
""" Load the predefined DB-Connections """
self.db_con_load()
""" Define the Labels """
db_con_label=tk.Label(top_frame,text="DB-Connection").grid(column=0,row=0,sticky=(tk.W))
db_name_label=tk.Label(top_frame,text="DB-Name").grid(column=1,row=0,sticky=(tk.W))
db_status_label=tk.Label(top_frame,text="DB-Status").grid(column=2,row=0,sticky=(tk.W))
db_conusr_label=tk.Label(top_frame,text="Connect-User").grid(column=3,row=0,sticky=(tk.W))
db_admusr_label=tk.Label(top_frame,text="Admin-User").grid(column=4,row=0,sticky=(tk.W))
db_secusr_label=tk.Label(top_frame,text="Security-User").grid(column=5,row=0,sticky=(tk.W))
""" Define the Entry-Fields """
db_con_entry=ttk.Combobox(top_frame,values=self.db_con_list,textvariable=self.db_con_var).grid(column=0,row=1,sticky=(tk.W))
db_con_entry.bind('<<ComboboxSelected>>', self.on_connect_select)
db_name_entry=ttk.Entry(top_frame,textvariable=self.db_name_var).grid(column=1,row=1,sticky=(tk.W))
db_status_entry=ttk.Entry(top_frame,textvariable=self.db_status_var).grid(column=2,row=1,sticky=(tk.W))
db_conusr_entry=ttk.Entry(top_frame,textvariable=self.db_conusr_var).grid(column=3,row=1,sticky=(tk.W))
db_admusr_entry=ttk.Entry(top_frame,textvariable=self.db_admusr_var).grid(column=4,row=1,sticky=(tk.W))
db_secusr_entry=ttk.Entry(top_frame,textvariable=self.db_secusr_var).grid(column=5,row=1,sticky=(tk.W))
""" Pack the Frames """
top_frame.pack()
left_frame.pack()
right_frame.pack()
center_frame.pack()
main_frame.pack()
python3 dssn.py
Exception in Tkinter callback
Traceback (most recent call last):
File "/usr/lib/python3.6/tkinter/__init__.py", line 1705, in __call__
return self.func(*args)
File "dssn.py", line 40, in logon_cmd
win=MainView(self.name_var.get())
File "dssn.py", line 92, in __init__
db_con_entry.bind('<<ComboboxSelected>>', self.on_connect_select)
AttributeError: 'NoneType' object has no attribute 'bind'
Was mache ich falsch. Wie es aussieht begehe ich in beiden Fällen den selben Fehler. Aber welchen!
Bitte helft mir. Ich bin wirklich am verzweifeln.
Ach ja ich habe einen Beitrag im Forum mit der selben Fehlermeldung gefunden.
Geholfen hat er mir leider nicht.