I am working on Computer Science Homework and having trouble with it the task is to create a gui with a button that opens a new window and displays information from the Swapi API (found at www.swapi.co) my problem is that it says im missing positional arguements and cannot figure out where they are missing or what i'm doing wrong for the Gui im using the tkinter module and I am also importing a class I made both the program and the class are located below
from tkinter import *
from People import Person
def FormatToString(collection):
results = ""
for item in collection:
response = requests.get(item)
dataRow = response.json()
results += " {}, ".format(dataRow['name'])
return results
def GetHomeWorld(homeworld):
response2 = requests.get(homeworld)
Json_data2 = response2.json()
homeworld = Json_data2['name']
return homeworld
root = Tk()
root.title('A visual Dictionary of the Star Wars Universe')
root.geometry('{}x{}'.format(460, 350))
# layout all of the main containers
root.grid_rowconfigure(1, weight=1)
root.grid_columnconfigure(0, weight=1)
# create all of the main containers
top_frame = Frame(root, bg='cyan',padx=100, pady=8)
center = Frame(root, bg='gray', padx=3, pady=3)
top_frame.grid(row=0, sticky="ew")
center.grid(row=1, sticky="nsew")
# create the widgets for the top frame
model_label = Label(top_frame, text='Filter Example')
width_label = Label(top_frame, text='Filter by keyword:')
entry_W = Entry(top_frame, background="pink")
def DataFilter():
root.title(entry_W.get())
center.destroy()
button = Button(top_frame, text="Submit", command=DataFilter)
# layout the widgets in the top frame
model_label.grid(row=0, columnspan=3)
width_label.grid(row=1, column=0)
entry_W.grid(row=1, column=1)
button.grid(row=1, column=2)
import json
import requests
starAPI = "https://swapi.co/api/people/"
response = requests.get(starAPI)
json_data = response.json()
i = 1
Label(center, text= 'StarShips\n=========', width=20, pady=13, padx=13).grid(row=1, column = 0)
Label(center, text= 'Name\n=====', width=20, pady=13, padx=13).grid(row=1, column = 1)
Label(center, text= 'Birth Year\n==========', width=20, pady=13, padx=13).grid(row=1, column = 2)
Label(center, text= 'Gender\n======', width=10, pady=13, padx=13).grid(row=1, column = 3)
Label(center, text= 'Eye Color\n=========', width=15, pady=13, padx=13).grid(row=1, column = 4)
Label(center, text= 'Homeworld\n========', width=15, pady=13, padx=13).grid(row=1, column = 5)
for person in (json_data['results']):
name = str(person['name'])
birth_year = str(person['birth_year'])
gender = str(person['gender'])
eye_color = str(person['eye_color'])
homeworld = GetHomeWorld(person['homeworld'])
starships = FormatToString(person['starships'])
i += 1
Button(center, text = 'Click Me for StarShips', width = 20, pady = 13, padx = 13, bg = 'black', fg = 'white', command = Person.openwindow(starships)).grid(row=i, column = 0)
Label(center, text= name, width=20, pady=13, padx=13).grid(row=i, column = 1)
Label(center, text= birth_year, width=20, pady=13, padx=13).grid(row=i, column = 2)
Label(center, text= gender, width=10, pady=13, padx=13).grid(row=i, column = 3)
Label(center, text= eye_color, width=15, pady=13, padx=13).grid(row=i, column = 4)
Label(center, text= homeworld, width=15, pady=13, padx=13).grid(row=i, column = 5
root.mainloop()
=====================================================================================================
import json
import requests
from tkinter import *
class Person():
def __init__(self, name, birth_year, eye_color, gender, homeworld, starships):
self.name = name
self.birth_year = birth_year
self.eye_color = eye_color
self.gender = gender
self.starships = self.FormatToString(starships)
self.homeworld = self.GetHomeWorld(homeworld)
def FormatToString(self, collection):
results = ""
for item in collection:
response = requests.get(item)
dataRow = response.json()
results += " {} |".format(dataRow['name'])
return results
def GetHomeWorld(self, homeworld):
response2 = requests.get(homeworld)
Json_data2 = response2.json()
homeworld = Json_data2['name']
return homeworld
def openwindow(self, starships):
window = Tk()
window.geometry('{}x{}'.format(460, 350))
window.title('Starships')
# layout all of the secondary containers
window.grid_rowconfigure(1, weight=1)
window.grid_columnconfigure(0, weight=1)
# create all of the secondary containers
top_frame2 = Frame(window, bg='cyan',padx=100, pady=8)
center2 = Frame(window, bg='gray', padx=3, pady=3)
top_frame2.grid(row=0, sticky="ew")
center2.grid(row=1, sticky="nsew")
Label(center2, text= starships, width=30, pady=13, padx=13).grid(row=0, column = 0)
window.mainloop
def __str__(self):
return "Name: {}\nBirth year: {}\nGender: {}\nEye Color: {}\nStarships: {}\nHomeworld: {}".format(self.name, self.birth_year, self.gender, self.eye_color, self.starships, self.homeworld)