mit tkinter will ich mir eine GUI für das Einrichten eines "Messprojektes" erstellen.
Jetzt möchte ich durch den Druck auf den button Fertigstellen eine Funktion ausführen lassen. Funktioniert aber nicht, ich weiß nicht was ich falsch mache.
Hier der code (entschuldigt bitte, dass es so viel ist, aber ich wollte nichts weg lassen, falls da etwas Kriegsentscheidendes dabei ist, das ganze Problem spiel sich unten ab bei der Erstellung des buttons fertigstellen, die Funktion Button kommt direkt danach):
Code: Alles auswählen
#! /usr/bin/env python
#
# GUI module generated by PAGE version 4.9
# In conjunction with Tcl version 8.6
# Dec 25, 2017 10:40:22 AM
import sys
try:
from Tkinter import *
except ImportError:
from tkinter import *
try:
import ttk
py3 = 0
except ImportError:
import tkinter.ttk as ttk
py3 = 1
import test_support
def vp_start_gui():
'''Starting point when module is the main routine.'''
global val, w, root
root = Tk()
top = New_Toplevel_1 (root)
test_support.init(root, top)
root.mainloop()
w = None
def create_New_Toplevel_1(root, *args, **kwargs):
'''Starting point when module is imported by another program.'''
global w, w_win, rt
rt = root
w = Toplevel (root)
top = New_Toplevel_1 (w)
test_support.init(w, top, *args, **kwargs)
return (w, top)
def destroy_New_Toplevel_1():
global w
w.destroy()
w = None
class New_Toplevel_1:
def __init__(self, top=None):
'''This class configures and populates the toplevel window.
top is the toplevel containing window.'''
_bgcolor = '#d9d9d9' # X11 color: 'gray85'
_fgcolor = '#000000' # X11 color: 'black'
_compcolor = '#d9d9d9' # X11 color: 'gray85'
_ana1color = '#d9d9d9' # X11 color: 'gray85'
_ana2color = '#d9d9d9' # X11 color: 'gray85'
self.style = ttk.Style()
if sys.platform == "win32":
self.style.theme_use('winnative')
self.style.configure('.',background=_bgcolor)
self.style.configure('.',foreground=_fgcolor)
self.style.configure('.',font="TkDefaultFont")
self.style.map('.',background=
[('selected', _compcolor), ('active',_ana2color)])
top.geometry("600x722+630+92")
top.title("New Toplevel 1")
top.configure(highlightcolor="black")
self.style.configure('TNotebook.Tab', background=_bgcolor)
self.style.configure('TNotebook.Tab', foreground=_fgcolor)
self.style.map('TNotebook.Tab', background=
[('selected', _compcolor), ('active',_ana2color)])
self.TNotebook1 = ttk.Notebook(top)
self.TNotebook1.place(relx=0.02, rely=0.01, relheight=0.97
, relwidth=0.97)
self.TNotebook1.configure(width=582)
self.TNotebook1.configure(takefocus="")
self.TNotebook1_t1 = ttk.Frame(self.TNotebook1)
self.TNotebook1.add(self.TNotebook1_t1, padding=3)
self.TNotebook1.tab(0, text="RTC auslesen",underline="-1",)
self.TNotebook1_t2 = ttk.Frame(self.TNotebook1)
self.TNotebook1.add(self.TNotebook1_t2, padding=3)
self.TNotebook1.tab(1, text="neues Projekt",underline="-1",)
self.Button1 = Button(self.TNotebook1_t1)
self.Button1.place(relx=0.02, rely=0.03, height=26, width=105)
self.Button1.configure(activebackground="#d9d9d9")
self.Button1.configure(text='''RTC auslesen''')
self.Label1 = Label(self.TNotebook1_t1)
self.Label1.place(relx=0.03, rely=0.1, height=578, width=536)
self.Label1.configure(justify=LEFT)
self.Label1.configure(text='''Label''')
self.Label1.configure(width=536)
self.Projektname = Entry(self.TNotebook1_t2)
self.Projektname.place(relx=0.21, rely=0.03, relheight=0.03
, relwidth=0.43)
self.Projektname.configure(background="white")
self.Projektname.configure(font="TkFixedFont")
self.Projektname.configure(width=246)
self.Label_projektname = Label(self.TNotebook1_t2)
self.Label_projektname.place(relx=0.03, rely=0.03, height=18, width=76)
self.Label_projektname.configure(anchor=SW)
self.Label_projektname.configure(text='''Projektname''')
self.Label_mess_beg = Label(self.TNotebook1_t2)
self.Label_mess_beg.place(relx=0.02, rely=0.22, height=18, width=126)
self.Label_mess_beg.configure(activebackground="#f9f9f9")
self.Label_mess_beg.configure(anchor=SW)
self.Label_mess_beg.configure(text='''Beginn der Messung''')
self.Label_mess_beg.configure(width=126)
self.entry_mess_beg_jahr = Entry(self.TNotebook1_t2)
self.entry_mess_beg_jahr.place(relx=0.28, rely=0.22, relheight=0.03
, relwidth=0.08)
self.entry_mess_beg_jahr.configure(background="white")
self.entry_mess_beg_jahr.configure(font="TkFixedFont")
self.entry_mess_beg_jahr.configure(selectbackground="#c4c4c4")
self.entry_mess_beg_jahr.configure(width=46)
self.Label_mess_ende = Label(self.TNotebook1_t2)
self.Label_mess_ende.place(relx=0.02, rely=0.26, height=18, width=126)
self.Label_mess_ende.configure(activebackground="#f9f9f9")
self.Label_mess_ende.configure(anchor=SW)
self.Label_mess_ende.configure(text='''Ende der Messung''')
self.Label_mess_ende.configure(width=126)
self.entry_mess_ende_jahr = Entry(self.TNotebook1_t2)
self.entry_mess_ende_jahr.place(relx=0.28, rely=0.26, relheight=0.03
, relwidth=0.08)
self.entry_mess_ende_jahr.configure(background="white")
self.entry_mess_ende_jahr.configure(font="TkFixedFont")
self.entry_mess_ende_jahr.configure(selectbackground="#c4c4c4")
self.entry_mess_ende_jahr.configure(width=46)
self.entry_mess_ende_monat = Entry(self.TNotebook1_t2)
self.entry_mess_ende_monat.place(relx=0.38, rely=0.26, relheight=0.03
, relwidth=0.08)
self.entry_mess_ende_monat.configure(background="white")
self.entry_mess_ende_monat.configure(font="TkFixedFont")
self.entry_mess_ende_monat.configure(selectbackground="#c4c4c4")
self.entry_mess_beg_monat = Entry(self.TNotebook1_t2)
self.entry_mess_beg_monat.place(relx=0.38, rely=0.22, relheight=0.03
, relwidth=0.08)
self.entry_mess_beg_monat.configure(background="white")
self.entry_mess_beg_monat.configure(font="TkFixedFont")
self.entry_mess_beg_monat.configure(selectbackground="#c4c4c4")
self.entry_mess_beg_monat.configure(width=46)
self.entry_mess_beg_tag = Entry(self.TNotebook1_t2)
self.entry_mess_beg_tag.place(relx=0.48, rely=0.22, relheight=0.03
, relwidth=0.08)
self.entry_mess_beg_tag.configure(background="white")
self.entry_mess_beg_tag.configure(font="TkFixedFont")
self.entry_mess_beg_tag.configure(selectbackground="#c4c4c4")
self.entry_mess_beg_tag.configure(width=46)
self.entry_mess_ende_tag = Entry(self.TNotebook1_t2)
self.entry_mess_ende_tag.place(relx=0.48, rely=0.26, relheight=0.03
, relwidth=0.08)
self.entry_mess_ende_tag.configure(background="white")
self.entry_mess_ende_tag.configure(font="TkFixedFont")
self.entry_mess_ende_tag.configure(selectbackground="#c4c4c4")
self.entry_mess_ende_tag.configure(width=46)
self.entry_mess_beg_std = Entry(self.TNotebook1_t2)
self.entry_mess_beg_std.place(relx=0.59, rely=0.22, relheight=0.03
, relwidth=0.08)
self.entry_mess_beg_std.configure(background="white")
self.entry_mess_beg_std.configure(cursor="fleur")
self.entry_mess_beg_std.configure(font="TkFixedFont")
self.entry_mess_beg_std.configure(selectbackground="#c4c4c4")
self.entry_mess_beg_std.configure(width=46)
self.entry_mess_ende_std = Entry(self.TNotebook1_t2)
self.entry_mess_ende_std.place(relx=0.59, rely=0.26, relheight=0.03
, relwidth=0.08)
self.entry_mess_ende_std.configure(background="white")
self.entry_mess_ende_std.configure(font="TkFixedFont")
self.entry_mess_ende_std.configure(selectbackground="#c4c4c4")
self.entry_mess_ende_std.configure(width=46)
self.entry_mess_beg_min = Entry(self.TNotebook1_t2)
self.entry_mess_beg_min.place(relx=0.69, rely=0.22, relheight=0.03
, relwidth=0.08)
self.entry_mess_beg_min.configure(background="white")
self.entry_mess_beg_min.configure(font="TkFixedFont")
self.entry_mess_beg_min.configure(selectbackground="#c4c4c4")
self.entry_mess_beg_min.configure(width=46)
self.entry_mess_ende_min = Entry(self.TNotebook1_t2)
self.entry_mess_ende_min.place(relx=0.69, rely=0.26, relheight=0.03
, relwidth=0.08)
self.entry_mess_ende_min.configure(background="white")
self.entry_mess_ende_min.configure(font="TkFixedFont")
self.entry_mess_ende_min.configure(selectbackground="#c4c4c4")
self.entry_mess_ende_min.configure(width=46)
self.Label_jahr = Label(self.TNotebook1_t2)
self.Label_jahr.place(relx=0.28, rely=0.19, height=18, width=28)
self.Label_jahr.configure(text='''Jahr''')
self.Label_monat = Label(self.TNotebook1_t2)
self.Label_monat.place(relx=0.38, rely=0.19, height=18, width=41)
self.Label_monat.configure(text='''Monat''')
self.Label_tag = Label(self.TNotebook1_t2)
self.Label_tag.place(relx=0.48, rely=0.19, height=18, width=26)
self.Label_tag.configure(text='''Tag''')
self.Label_std = Label(self.TNotebook1_t2)
self.Label_std.place(relx=0.59, rely=0.19, height=18, width=48)
self.Label_std.configure(text='''Stunde''')
self.Label_minu = Label(self.TNotebook1_t2)
self.Label_minu.place(relx=0.69, rely=0.19, height=18, width=45)
self.Label_minu.configure(text='''Minute''')
self.Butt_ab_sofort = Button(self.TNotebook1_t2)
self.Butt_ab_sofort.place(relx=0.79, rely=0.22, height=26, width=79)
self.Butt_ab_sofort.configure(activebackground="#d9d9d9")
self.Butt_ab_sofort.configure(text='''ab sofort''')
self.Butt_fertig = Button(self.TNotebook1_t2)
self.Butt_fertig.place(relx=0.03, rely=0.44, height=26, width=97)
self.Butt_fertig.configure(activebackground="#d9d9d9")
self.Butt_fertig.configure(text='''fertigstellen''', command=self.press_button)
def press_button(self):
print "hallo"
#print self.Projektname.get()
if __name__ == '__main__':
vp_start_gui()
Code: Alles auswählen
Traceback (most recent call last):
File "project_config.py", line 244, in <module>
vp_start_gui()
File "project_config.py", line 26, in vp_start_gui
top = New_Toplevel_1 (root)
File "project_config.py", line 234, in __init__
self.Butt_fertig.configure(text='''fertigstellen''', command=self.press_button)
AttributeError: New_Toplevel_1 instance has no attribute 'press_button'
Ich weiß, ich muss mich unbedingt sehr intensiv mit Klassen beschäftigen...