PySimpleGUI: How to not display empty field - hide

I've created the simple GUI as follow.
In the example only three rows are included, however the same principle can be applied to more of them.
I would like to fill all or same rows in the GUI and the save it, but most importantly when the saved files is loaded back only the filled rows (and not all) should be displayed.
I've tried in the way below but unsuccessfully..
import PySimpleGUI as sg
from datetime import datetime
import base64
from pathlib import Path
import webbrowser
sg.theme('DarkTeal9')
layout_1 = [[sg.InputText("", key="-IT2-", font='Arial 9', size=(10,1)),
sg.Combo(["Item1", "Item2", "Item3"],size=(20,1), key='-TEST2-', font='Arial 9'),
sg.CalendarButton("", close_when_date_chosen=True, target='-IN2-', font='Arial 9', no_titlebar=False, format='%d-%b-%Y'),
sg.InputText("", key='-IN2-', size=(20,1), font='Arial 9')]]
layout_a = [[sg.Button("row 2")]]
layout_2 = [[sg.InputText("", key="-IT3-", font='Arial 9', size=(10,1)),
sg.Combo(["Item1", "Item2", "Item3"],size=(20,1), key='-TEST3-', font='Arial 9'),
sg.CalendarButton("", close_when_date_chosen=True, target='-IN3-', font='Arial 9', no_titlebar=False, format='%d-%b-%Y'),
sg.InputText("", key='-IN3-', size=(20,1), font='Arial 9')]]
layout_b =[[sg.Button("row 3")]]
layout_3 = [[sg.InputText("", key="-IT4-", font='Arial 9', size=(10,1), visible=True),
sg.Combo(["Item1", "Item2", "Item3"],size=(20,1), key='-TEST4-', font='Arial 9'),
sg.CalendarButton("", close_when_date_chosen=True, target='-IN4-', font='Arial 9', no_titlebar=False, format='%d-%b-%Y'),
sg.InputText("", key='-IN4-', size=(20,1), font='Arial 9', justification="c")]]
layout = [
[sg.Column(layout_1, key='-LAY1-'), sg.Column(layout_a, visible=True, key="-LAYA-")],
[sg.Column(layout_2, visible=False, key='-LAY2-'), sg.Column(layout_b, visible=False, key='-LAYB-')],
[sg.Column(layout_3, visible=False, key='-LAY3-')],
[sg.Button ("Save"), sg.Button ("Load"), sg.Button('Exit'),],
]
window = sg.Window("", layout)
while True:
event, values = window.read()
if event == 'Save':
file_name = sg.popup_get_file("Save", save_as=True, no_window=True)
window.SaveToDisk(file_name)
if event == 'Load':
file_name = sg.popup_get_file('Load', no_window=True)
window.LoadFromDisk(file_name)
if values["-IT2-"] != "":
window[f'-LAY1-'].update(visible=True)
window[f'-LAYA-'].update(visible=False)
if values ["-IT3-"] != "":
window[f'-LAY2-'].update(visible=True)
if values["-IT4-"] != "":
window[f'-LAY3-'].update(visible=True)
if event == sg.WIN_CLOSED or event == 'Exit':
break
window.close()
if event == 'row 2':
window[f'-LAY2-'].update(visible=True)
window[f'-LAYA-'].update(visible=False)
window[f'-LAYB-'].update(visible=True)
layout = str(event)
if event == 'row 3':
window[f'-LAY3-'].update(visible=True)
window[f'-LAYB-'].update(visible=False)
layout = str(event)
window.close()

Try it
if event == 'Load':
file_name = sg.popup_get_file('Load', no_window=True)
window.LoadFromDisk(file_name)
v1, v2, v3 = window["-IT2-"].get(), window["-IT3-"].get(), window["-IT4-"].get()
if v1:
window[f'-LAY1-'].update(visible=True)
window[f'-LAYA-'].update(visible=False)
if v2:
window[f'-LAY2-'].update(visible=True)
if v3:
window[f'-LAY3-'].update(visible=True)

Related

scatter plot with Dash

I am coding a Dash page to plot some data for myself.
I want to have some dynamic features on some of my plots.
On my dash I have one dropdown, one pie chart and one scatter chart.
Here is my code:
import dash
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output
import plotly.graph_objs as go
app = dash.Dash()
app.layout = html.Div([
html.Label(['Select the Type:']),
dcc.Dropdown(
id='type_filter',
options=[{'label': i, 'value': i} for i in df.Type.unique()],
value='All'
),
dcc.Graph(
id='allocation_chart'
),
dcc.Graph(
id='allocation_history_chart'
),
])
#app.callback(
Output('allocation_chart','figure'),
[
Input('type_filter', 'value')
]
)
def update_allocation(type_):
if type_ == 'All':
filtered = df
else:
mask = df['Type'] == type_
filtered = df.loc[mask]
data = [
go.Pie(
labels=filtered['Asset'],
values=filtered['Total']
)
]
return {
'data': data,
'layout': go.Layout(title='Asset Allocation by Type')
}
#app.callback(
Output('allocation_history_chart','figure'),
[
Input('type_filter','value')
]
)
def update_allocation_history(type_):
if type_ == 'All':
filtered = df_index
else:
mask = df['Type'] == type_
filtered = df_index.loc[mask]
data = go.Figure()
for ticker in filtered.index:
data.add_trace(
go.Scatter(
x = filtered.loc[ticker].index,
y = filtered.loc[ticker],
name = ticker
)
)
return {
'data': [data],
'layout': go.Layout(title='History of Asset')
}
if __name__ == '__main__':
app.run_server()
here is the Dash:
Here is the scatter chart ran in my Notebook:
Everything is working - Dash is running well, i can see the dropdown and the pie chart - except the scatter chart - the second one.
I absolutely don't understand why because when I run the scatter chart in my Notebook it's working pretty well.
If you have any idea, don't hesitate.

on dropdown select show n% of inputs

im trying to show a dropdown input based on the selected item in a "main" dropdown.
dropdown main is numberer from 0 to 5
i need that on selection of for example 3 it opens bellow 3 dropdown inputs
this can easily be done with jquery but im making a small app 100% python
this is what i got so far
labdrop = Label(frmConf,width="18", text="Test:", anchor='w')
labdrop.pack(side=LEFT)
options = ['1', '2', '3', '4', '5',]
clicked = StringVar()
clicked.set(options[0])
drop = OptionMenu(frmConf, clicked, *options, command=slotstypes)
drop.pack(anchor=W)
def slotstypes():
i=int(1)
a = int(clicked.get(options))
print(a)
while i < a:
labdrop = Label(frmConf, width="18", text="got it", anchor='w').pack(side=LEFT)
i += 1
got this error
a = int(clicked.get(options))
AttributeError: 'str' object has no attribute 'get'
thanks in advance
done it
labdrop = Label(frmConf,width="18", text="Test:", anchor='w')
labdrop.pack(side=LEFT)
options = ['1', '2', '3', '4', '5',]
clicked = StringVar()
clicked.set(options[0])
drop = OptionMenu(frmConf, clicked, *options, command=slotstypes)
drop.pack(anchor=W)
def slotstypes():
i=int(1)
a = int(clicked)
print(a)
while i < a:
labdrop = Label(frmConf, width="18", text="got it", anchor='w').pack(side=LEFT)
i += 1

How to fix 'Dropdown Menu Read' Error in Plotly Dash

I have tried to re-create the following example Towards Data Science Example shown on the web
I have written the following code which I modified to this:
import dash
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output
import pandas as pd
import plotly.graph_objs as go
# Step 1. Launch the application
app = dash.Dash()
# Step 2. Import the dataset
filepath = 'https://raw.githubusercontent.com/plotly/datasets/master/finance-charts-apple.csv'
st = pd.read_csv(filepath)
# range slider options
st['Date'] = pd.to_datetime(st.Date)
dates = ['2015-02-17', '2015-05-17', '2015-08-17', '2015-11-17',
'2016-02-17', '2016-05-17', '2016-08-17', '2016-11-17', '2017-02-17']
features = st.columns[1:-1]
opts = [{'label' : i, 'value' : i} for i in features]
# Step 3. Create a plotly figure
trace_1 = go.Scatter(x = st.Date, y = st['AAPL.High'],
name = 'AAPL HIGH',
line = dict(width = 2,
color = 'rgb(229, 151, 50)'))
layout = go.Layout(title = 'Time Series Plot',
hovermode = 'closest')
fig = go.Figure(data = [trace_1], layout = layout)
# Step 4. Create a Dash layout
app.layout = html.Div([
# a header and a paragraph
html.Div([
html.H1("This is my first dashboard"),
html.P("Dash is so interesting!!")
],
style = {'padding' : '50px' ,
'backgroundColor' : '#3aaab2'}),
# adding a plot
dcc.Graph(id = 'plot', figure = fig),
# dropdown
html.P([
html.Label("Choose a feature"),
dcc.Dropdown(
id='opt',
options=opts,
value=features[0],
multi=True
),
# range slider
html.P([
html.Label("Time Period"),
dcc.RangeSlider(id = 'slider',
marks = {i : dates[i] for i in range(0, 9)},
min = 0,
max = 8,
value = [1, 7])
], style = {'width' : '80%',
'fontSize' : '20px',
'padding-left' : '100px',
'display': 'inline-block'})
])
])
# Step 5. Add callback functions
#app.callback(Output('plot', 'figure'),
[Input('opt', 'value'),
Input('slider', 'value')])
def update_figure(input1, input2):
# filtering the data
st2 = st[(st.Date > dates[input2[0]]) & (st.Date < dates[input2[1]])]
# updating the plot
trace_1 = go.Scatter(x = st2.Date, y = st2['AAPL.High'],
name = 'AAPL HIGH',
line = dict(width = 2,
color = 'rgb(229, 151, 50)'))
trace_2 = go.Scatter(x = st2.Date, y = st2[input1],
name = str(input1),
line = dict(width = 2,
color = 'rgb(106, 181, 135)'))
fig = go.Figure(data = [trace_1, trace_2], layout = layout)
return fig
# Step 6. Add the server clause
if __name__ == '__main__':
app.run_server(debug = True)
When I change the feature input, it does not update the plot correctly and does not show the selected features in the plot.
Either there is something wrong with the callback function or the initialization of the graph with the second trace. But I cant figure out where the issue is.
As you are only providing two scatter traces within your callback. From both, one is static for 'AAPL.High'. So you need to limit the dropdown values to Multi=False.
Valid plots are only generated for choosing options like 'AAPL.LOW' and others like dic won't display a second trace. The callback wouldn't terminate if you would keepmulti=True the callback would stil work, if always only one option is selected. The moment you select two or more options the script will fail as it would try to find faulty data for the data return block here:
trace_2 = go.Scatter(x = st2.Date, y = st2[**MULTIINPUT**],
name = str(input1),
line = dict(width = 2,
color = 'rgb(106, 181, 135)'))
Only one column id is allowed to be passed at MULTIINPUT. If you want to introduce more traces please use a for loop.
Change the code to the following:
import dash
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output
import pandas as pd
import plotly.graph_objs as go
# Step 1. Launch the application
app = dash.Dash()
# Step 2. Import the dataset
filepath = 'https://raw.githubusercontent.com/plotly/datasets/master/finance-charts-apple.csv'
st = pd.read_csv(filepath)
# range slider options
st['Date'] = pd.to_datetime(st.Date)
dates = ['2015-02-17', '2015-05-17', '2015-08-17', '2015-11-17',
'2016-02-17', '2016-05-17', '2016-08-17', '2016-11-17', '2017-02-17']
features = st.columns
opts = [{'label' : i, 'value' : i} for i in features]
# Step 3. Create a plotly figure
trace_1 = go.Scatter(x = st.Date, y = st['AAPL.High'],
name = 'AAPL HIGH',
line = dict(width = 2,
color = 'rgb(229, 151, 50)'))
layout = go.Layout(title = 'Time Series Plot',
hovermode = 'closest')
fig = go.Figure(data = [trace_1], layout = layout)
# Step 4. Create a Dash layout
app.layout = html.Div([
# a header and a paragraph
html.Div([
html.H1("This is a Test Dashboard"),
html.P("Dash is great!!")
],
style = {'padding' : '50px' ,
'backgroundColor' : '#3aaab2'}),
# adding a plot
dcc.Graph(id = 'plot', figure = fig),
# dropdown
html.P([
html.Label("Choose a feature"),
dcc.Dropdown(
id='opt',
options=opts,
value=features[0],
multi=False
),
# range slider
html.P([
html.Label("Time Period"),
dcc.RangeSlider(id = 'slider',
marks = {i : dates[i] for i in range(0, 9)},
min = 0,
max = 8,
value = [1, 7])
], style = {'width' : '80%',
'fontSize' : '20px',
'padding-left' : '100px',
'display': 'inline-block'})
])
])
# Step 5. Add callback functions
#app.callback(Output('plot', 'figure'),
[Input('opt', 'value'),
Input('slider', 'value')])
def update_figure(input1, input2):
# filtering the data
st2 = st#[(st.Date > dates[input2[0]]) & (st.Date < dates[input2[1]])]
# updating the plot
trace_1 = go.Scatter(x = st2.Date, y = st2['AAPL.High'],
name = 'AAPL HIGH',
line = dict(width = 2,
color = 'rgb(229, 151, 50)'))
trace_2 = go.Scatter(x = st2.Date, y = st2[input1],
name = str(input1),
line = dict(width = 2,
color = 'rgb(106, 181, 135)'))
fig = go.Figure(data = [trace_1, trace_2], layout = layout)
return fig
# Step 6. Add the server clause
if __name__ == '__main__':
app.run_server(debug = True)
I hope this cleared things up and solved your issues. :)

Plotly Dash Graph With Multiple Dropdown Inputs Not Working

I’m trying to create a time-series Dash line graph that has multiple interactive dropdown user input variables. I would ideally like each of the dropdown inputs to allow for multiple selections.
While I’m able to create the drop down menus successfully, the chart isn’t updating like I’d like. When I allow the dropdowns to have multiple selections, I get an error that arrays are different lengths. And when I limit the dropdowns to one selection, I get an error that [‘Vendor_Name’] is not in index. So this may be two separate problems.
Graph that doesn’t work:
Snippet of Excel data imported into DF
import dash
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output
import pandas as pd
#import plotly.graph_objs as go
df = pd.read_csv("Data.csv", sep = "\t")
df['YearMonth'] = pd.to_datetime(df['YearMonth'], format = '%Y-%m')
cols = ['Product_1', 'Product_2', 'Product_3']
vendor = df['Vendor'].unique()
app = dash.Dash('Data')
app.layout = html.Div([
html.Div([
html.Div([
html.Label('Product'),
dcc.Dropdown(
id = 'product',
options = [{
'label' : i,
'value' : i
} for i in cols],
multi = True,
value = 'Product_1'
),
]),
html.Div([
html.Label('Vendor'),
dcc.Dropdown(
id = 'vendor',
options = [{
'label' : i,
'value' : i
} for i in vendor],
multi = True,
value = 'ABC')
,
]),
]),
dcc.Graph(id = 'feature-graphic')
])
#app.callback(Output('feature-graphic', 'figure'),
[Input('product', 'value'),
Input('vendor', 'value')])
def update_graph(input_vendor, input_column):
df_filtered = df[df['Vendor'] == input_vendor]
##also tried setting an index because of the error I was getting. Not sure if necessary
df_filtered = df_filtered.set_index(['Vendor'])
traces = []
df_by_col = df_filtered[[input_column, 'YearMonth']]
traces.append({
'x' :pd.Series(df_by_col['YearMonth']),
'y' : df_by_col[input_column],
'mode' : 'lines',
'type' : 'scatter',
'name' :'XYZ'}
)
fig = {
'data': traces,
'layout': {'title': 'Title of Chart'}
}
return fig
if __name__ == '__main__':
app.run_server(debug=False)
Thanks in advance for helping! Still new-ish to Python, but very excited about Dash’s capabilities. I’ve been able to create other graphs with single inputs, and have read through documentation.
Here is the approach I followed: (editing common example available in google with my approach):
import dash
from dash.dependencies import Input, Output
import dash_core_components as dcc
import dash_html_components as html
app = dash.Dash(__name__)
all_options = {
'America': ['New York City', 'San Francisco', 'Cincinnati'],
'Canada': [u'Montréal', 'Toronto', 'Ottawa']
}
app.layout = html.Div([
dcc.Dropdown(
id='countries-dropdown',
options=[{'label': k, 'value': k} for k in all_options.keys()],
value='America', #default value to show
multi=True,
searchable=False
),
dcc.Dropdown(id='cities-dropdown', multi=True, searchable=False, placeholder="Select a city"),
html.Div(id='display-selected-values')
])
#app.callback(
dash.dependencies.Output('cities-dropdown', 'options'),
[dash.dependencies.Input('countries-dropdown', 'value')])
def set_cities_options(selected_country):
if type(selected_country) == 'str':
return [{'label': i, 'value': i} for i in all_options[selected_country]]
else:
return [{'label': i, 'value': i} for country in selected_country for i in all_options[country]]
if __name__ == '__main__':
app.run_server(debug=True)
Workaround here is: When there is single input present in parent dropdown, the value is in string format. But for multiple values, it comes in list format.
This code also work perfectly and gets updated automatically even when you click on cross option to remove any selected option.
Note: I have used 'placeholder' attribute instead of defining default value for it as it made no sense in this case. But you can also update the value dynamically in similar way.
1 input data
The data as it is in the csv is hard to loop.
And I would argue that it is the main reason your code does not work,
because you seem to understand the fundamental code structure.
Having put on my SQL glasses I think you should try to get it to sth like
Date, Vendor, ProductName, Value
2 callback input types change
multi is tricky because it changes switches between returning a str if only 1 item is selected and list if more than one is selected
3 callback return type
you code returns a dict but the callback declared figure as the return type
but here is the code with debugging traces of print() and sleep()
import pandas as pd
import dash
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output
import plotly.graph_objs as go
import time
df = pd.read_csv("Data.csv", sep="\t")
df['YearMonth'] = pd.to_datetime(df['YearMonth'], format='%Y-%m')
products = ['Product_1', 'Product_2', 'Product_3']
vendors = df['Vendor'].unique()
app = dash.Dash('Data')
app.layout = html.Div([
html.Div([
html.Div([
html.Label('Product'),
dcc.Dropdown(
id='product',
options=[{'label' : p, 'value' : p} for p in products],
multi=True,
value='Product_1'
),
]),
html.Div([
html.Label('Vendor'),
dcc.Dropdown(
id='vendor',
options=[{'label': v, 'value': v} for v in vendors],
multi=True,
value='ABC'
),
]),
]),
dcc.Graph(id='feature-graphic', figure=go.Figure())
])
#app.callback(
Output('feature-graphic', 'figure'),
[Input('product', 'value'),
Input('vendor', 'value')])
def update_graph(input_product, input_vendor):
# df_filtered[['Product_1', 'YearMonth']]
if type(input_product) == str:
input_product = [input_product]
if type(input_vendor) == str:
input_vendor= [input_vendor]
datasets = ['']
i = 1
for vendor in input_vendor:
df_filtered = df[df['Vendor'] == vendor]
for product in input_product:
datasets.append((df_filtered[['YearMonth', 'Vendor', product]]).copy())
datasets[i]['ProductName'] = product
datasets[i].rename(columns={product: 'Value'}, inplace=True)
i += 1
datasets.pop(0)
print(datasets)
traces = ['']
for dataset in datasets:
print(dataset)
time.sleep(1)
traces.append(
go.Scatter({
'x': dataset['YearMonth'],
'y': dataset['Value'],
'mode': 'lines',
'name': f"Vendor: {dataset['Vendor'].iloc[0]} Product: {dataset['ProductName'].iloc[0]}"
}))
traces.pop(0)
layout = {'title': 'Title of Chart'}
fig = {'data': traces, 'layout': go.Layout(layout)}
return go.Figure(fig)
if __name__ == '__main__':
app.run_server()
quick and dirty disclosure:
If you handle the 1. issue it will dramatically simplify everything.
So I'd try to isolate the pd.DataFrame() juggling out of the callback and into the upper I/O part.
1) don't use counters in for loops
2) my variable names aren't the best either
3) the following style is caveman's python and there must be a better way:
traces = ['']
traces.append(this_and_that)
traces.pop(0)
Generally:
using print(input_variable) and print(type(input_variable))
gets my wheels most of the time out of the mud.
after all
you should notice that each trace got its individual name which will show up in the legend. Clicking on the name in the legend will add or remove the trace without the need for#app.callback()

Python object method is seeing self argument as missing

I am making a text based game to teach myself python. I try to access the attribute of an object stored in the player object. The object is a copy of the map data object representing their position on the map.
When i run the function as it is, when the look method of the player object is called, the method sees the self argument as a missing argument. If I try to access the room data stored in the player object and pass it in (which doesn't seem right anyway as it should already be in the object instance), it then says the attribute doesn't exist. After the program crashes, in the interpreter I can access the attribute without error. I don't understand what I am doing wrong.
class quadPoint:
def __init__(self, data):
self.pointData = {'description' : '', 'west': '','east': '',
'north': '','south': ''}
self.exits = []
self.inventory = []
self.pointData['description'] = data[0]
self.pointData['west'] = data[1]
self.pointData['east'] = data[2]
self.pointData['north'] = data[3]
self.pointData['south'] = data[4]
def addItem(self, item):
self.inventory.append(item)
def addExit(self, ext):
self.exits.append(ext)
rooms = [
['A discription1','A discription','A discription','A discription','A discription'],
['A discription2','A discription','A discription','A discription','A discription'],
['A discription3','A discription','A discription','A discription','A discription'],
['A discription4','A discription','A discription','A discription','A discription'],
['A discription5','A discription','A discription','A discription','A discription'],
['A discription6','A discription','A discription','A discription','A discription'],
['A discription7','A discription','A discription','A discription','A discription'],
['A discription8','A discription','A discription','A discription','A discription'],
['A discription9','A discription','A discription','A discription','A discription']
]
roomExits = {
'00':[ [0,1],[1,0] ], # 0,0
'01':[ [0,0],[0,2],[1,1] ], # 0,1
'02':[ [0,1],[1,2] ], # 0,2
'10':[ [0,0],[1,1],[2,0] ], # 1,0
'11':[ [1,0],[1,2],[0,1],[2,1] ], # 1,1
'12':[ [1,1],[2,2] ], # 1,2
'20':[ [1,0],[2,1] ], # 2,0
'21':[ [2,0],[1,1],[2,2] ], # 2,1
'22':[ [2,1],[1,2] ], # 2,2
}
class World :
def __init__(self, data, exits):
self.worldData = [ [],[],[] ]
self.generate(data, exits)
def getRoom(self,x,y):
return self.worldData[x][y]
def generate(self, data, exits):
ph = 0
for array in self.worldData:
for i in range(0,3):
array.append('')
for x in range(0,3):
for i in range(0,3):
self.worldData[x][i] = quadPoint(data[ph])
ph += 1
for quards in exits:
for e in exits[quards]:
self.worldData[int(quards[0])][int(quards[1])].addExit(self.worldData[e[0]][e[1]])
class Player :
def __init__(self, room):
self.statData = {}
self.equipment = { 'head' : '', 'neck' : '', 'leftEar' : '',
'rightEar' : '', 'leftShoulder' : '',
'rightShoulder' : '', 'chest' : '',
'leftUpperArm' : '', 'rightUpperArm' : '',
'leftLowerArm' : '', 'rightLowerArm' : '',
'leftFinger0' : '','leftFinger1' : '',
'leftFinger2' : '','leftFinger3' : '',
'leftFinger4' : '','rightFinger0' : '',
'rightFinger1' : '','rightFinger2' : '',
'rightFinger3' : '','rightFinger4' : '',
'leftWrist' : '','rightWrist' : '',
'upperBack' : '','lowerBack' : '','back' : '','Waist' : '',
'leftUpperLeg' : '','rightUpperLeg' : '',
'leftLowerLeg' : '','rightLowerLeg' : '',
'leftAnkle' : '','rightAnkle' : '',
'leftFoot' : '','rightFoot' : ''}
print("What would you like your name to be?")
print()
self.name = input(">>> ")
print('''What would you like your name to be
Wizard
Fighter
Thief
''')
self.plrClass = input(">>> ")
self.currentRoom = room
def look(self, where):
return self.currentRoom.pointData[where]
class Game :
def __init__(self):
self.world = World(rooms, roomExits)
self.player = Player(self.world.getRoom(0,0))
def start(self):
self.running = True
while self.running is True:
print(player.look( 'description'))
print()
print("What do you want to do?")
print()
usrInput = input(">>> ")
if userInput == 'quit': self.running = False
game = Game()
game.start()
the error message is:
Traceback (most recent call last):
File "/home/groundscore/pytextrpg.py", line 128, in <module>
game.start()
File "/home/groundscore/pytextrpg.py", line 117, in start
print(player.look( 'description'))
TypeError: look() takes exactly 2 arguments (1 given)
aruisdante beat me to the immediate answer. A deeper problem, and the reason for the particular error message is using the same lowercase word for both class and instance thereof. If the player class were Player, then print(player...) would have failed with NameError: name 'player' is not defined and you would not have seen the confusing message that resulted from player.look being resolved as the look attribute of the player class.
Also, game = game() is more confusing than game = Game(), and prevents further access to the game class by its name.
I'm not exactly sure if you're properly describing your error (it would be helpful if you included the exact error text, not your description of it), but certainly here:
print(player.look( 'description'))
Should instead be:
print(self.player.look( 'description'))
As player is an attribute of the game class. Also, you should not use is for string comparisons, you should use ==.

Resources