When I try to open my Python script, it gives me this error:
Traceback (most recent call last):
File "gui.py", line 111, in <module>
vp_start_gui()
File "gui.py", line 30, in vp_start_gui
top = Toplevel1 (root)
File "gui.py", line 79, in __init__
self.Button1.configure(command=self.getTemp())
File "gui.py", line 105, in getTemp
this.plz = this.Entry1.get()
AttributeError: Toplevel1 instance has no attribute 'Entry1'
I googled the error but I haven't got any similar results. Also, the attribute Entry1 exists as you can see in the code. And I'm using the correct command to access Entry1.
Full code:
#! /usr/bin/env python
# -*- coding: utf-8 -*-
#
# GUI module generated by PAGE version 4.22
# in conjunction with Tcl version 8.6
# Apr 24, 2019 01:22:16 PM CEST platform: Darwin
import sys
import requests
import json
try:
import Tkinter as tk
except ImportError:
import tkinter as tk
try:
import ttk
py3 = False
except ImportError:
import tkinter.ttk as ttk
py3 = True
import unknown_support
def vp_start_gui():
'''Starting point when module is the main routine.'''
global val, w, root
root = tk.Tk()
top = Toplevel1 (root)
unknown_support.init(root, top)
root.mainloop()
w = None
def create_Toplevel1(root, *args, **kwargs):
'''Starting point when module is imported by another program.'''
global w, w_win, rt
rt = root
w = tk.Toplevel (root)
top = Toplevel1 (w)
unknown_support.init(w, top, *args, **kwargs)
return (w, top)
def destroy_Toplevel1():
global w
w.destroy()
w = None
class Toplevel1:
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 = '#ececec' # Closest X11 color: 'gray92'
key = "xxx" # API KEY von openweathermaps eintragen
url = "https://api.openweathermap.org/data/2.5/weather?zip="
parameters = ",DE&units=metric&appid=" + str(key)
data = ""
json = ""
top.geometry("144x142+586+143")
top.title("New Toplevel")
top.configure(background="#d9d9d9")
self.Button1 = tk.Button(top)
self.Button1.place(relx=0.208, rely=0.352, height=32, width=77)
self.Button1.configure(activebackground="#ececec")
self.Button1.configure(activeforeground="#000000")
self.Button1.configure(background="#d9d9d9")
self.Button1.configure(cursor="fleur")
self.Button1.configure(foreground="#000000")
self.Button1.configure(highlightbackground="#d9d9d9")
self.Button1.configure(highlightcolor="black")
self.Button1.configure(text='''GET''')
self.Button1.configure(width=77)
self.Button1.configure(command=self.getTemp())
self.Entry1 = tk.Entry(top)
self.Entry1.place(relx=0.069, rely=0.07,height=27, relwidth=0.847)
self.Entry1.configure(background="white")
self.Entry1.configure(cursor="fleur")
self.Entry1.configure(font="TkFixedFont")
self.Entry1.configure(foreground="#000000")
self.Entry1.configure(insertbackground="black")
self.Entry1.configure(width=122)
self.Text1 = tk.Text(top)
self.Text1.place(relx=0.069, rely=0.634, relheight=0.296, relwidth=0.889)
self.Text1.configure(background="white")
self.Text1.configure(font="TkTextFont")
self.Text1.configure(foreground="black")
self.Text1.configure(highlightbackground="#d9d9d9")
self.Text1.configure(highlightcolor="black")
self.Text1.configure(insertbackground="black")
self.Text1.configure(selectbackground="#c4c4c4")
self.Text1.configure(selectforeground="black")
self.Text1.configure(width=128)
self.Text1.configure(wrap="word")
def getTemp(self):
self.plz = self.Entry1.get()
self.data = requests.get(self.url + str(self.plz) + self.parameters)
self.json = json.loads(self.data.text)
self.Text1.configure(text="Stadt: " + str(self.json["name"]) + "\nTemperatur: " + str(self.json["main"]["temp"]))
if __name__ == '__main__':
vp_start_gui()
I expect another error with this line:
self.Text1.configure(text="Stadt: " + str(this.json["name"]) + "\nTemperatur: " + str(this.json["main"]["temp"]))
Otherwise it should run. I didn't add much code to the gui script.
EDIT Ok, now I have the full working code:
#! /usr/bin/env python
# -*- coding: utf-8 -*-
#
# GUI module generated by PAGE version 4.22
# in conjunction with Tcl version 8.6
# Apr 24, 2019 01:22:16 PM CEST platform: Darwin
import sys
import requests
import json
try:
import Tkinter as tk
except ImportError:
import tkinter as tk
try:
import ttk
py3 = False
except ImportError:
import tkinter.ttk as ttk
py3 = True
import unknown_support
def vp_start_gui():
'''Starting point when module is the main routine.'''
global val, w, root
root = tk.Tk()
top = Toplevel1 (root)
unknown_support.init(root, top)
root.mainloop()
w = None
def create_Toplevel1(root, *args, **kwargs):
'''Starting point when module is imported by another program.'''
global w, w_win, rt
rt = root
w = tk.Toplevel (root)
top = Toplevel1 (w)
unknown_support.init(w, top, *args, **kwargs)
return (w, top)
def destroy_Toplevel1():
global w
w.destroy()
w = None
class Toplevel1:
key = "xxx" # API KEY von openweather
url = "https://api.openweathermap.org/data/2.5/weather?zip="
parameters = ",DE&units=metric&appid=" + str(key)
data = ""
json = ""
def __init__(self, top=None):
'''self 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 = '#ececec' # Closest X11 color: 'gray92'
top.geometry("144x142+586+143")
top.title("New Toplevel")
top.configure(background="#d9d9d9")
self.Button1 = tk.Button(top)
self.Button1.place(relx=0.208, rely=0.352, height=32, width=77)
self.Button1.configure(activebackground="#ececec")
self.Button1.configure(activeforeground="#000000")
self.Button1.configure(background="#d9d9d9")
self.Button1.configure(cursor="fleur")
self.Button1.configure(foreground="#000000")
self.Button1.configure(highlightbackground="#d9d9d9")
self.Button1.configure(highlightcolor="black")
self.Button1.configure(text='''GET''')
self.Button1.configure(width=77)
self.Button1.configure(command= lambda: self.getTemp())
self.Entry1 = tk.Entry(top)
self.Entry1.place(relx=0.069, rely=0.07,height=27, relwidth=0.847)
self.Entry1.configure(background="white")
self.Entry1.configure(cursor="fleur")
self.Entry1.configure(font="TkFixedFont")
self.Entry1.configure(foreground="#000000")
self.Entry1.configure(insertbackground="black")
self.Entry1.configure(width=122)
self.Text1 = tk.Text(top)
self.Text1.place(relx=0.069, rely=0.634, relheight=0.296, relwidth=0.889)
self.Text1.configure(background="white")
self.Text1.configure(font="TkTextFont")
self.Text1.configure(foreground="black")
self.Text1.configure(highlightbackground="#d9d9d9")
self.Text1.configure(highlightcolor="black")
self.Text1.configure(insertbackground="black")
self.Text1.configure(selectbackground="#c4c4c4")
self.Text1.configure(selectforeground="black")
self.Text1.configure(width=128)
self.Text1.configure(wrap="word")
def getTemp(self):
self.plz = self.Entry1.get()
self.data = requests.get(self.url + str(self.plz) + self.parameters)
self.json = json.loads(self.data.text)
self.Text1.insert(tk.END, "Stadt: " + str(self.json["name"]) + "\nTemperatur: " + str(self.json["main"]["temp"]))
if __name__ == '__main__':
vp_start_gui()