I am new to programming and just started trying a blackjack game using PySimpleGUI. I don't know why I am getting error on the line event,values = window.Read() in the end. Any help is appreciated.
import PySimpleGUI as sg
import random
# Creating multiple varibales to be used throughout
deck = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
hand = []
dealer_hand = []
random1 = random.randint(1,10)
random2 = random.randint(1,10)
dealer1 = random.randint(1,10)
dealer2 = random.randint(1,10)
welcome = [ [sg.Text('Welcome to blackjack', text_color='#000000', font=('Times New Roman',
16,'bold'))],
[sg.Text('Rules: You will be dealt 2 cards and the same for the dealer. The dealer will',
text_color='#000000')],
[sg.Text(' only reveal one of his cards. Your objective is to reach close to 21 without crossing it',
text_color='#000000')],
[sg.Text(' Aces can be 1 or 11, all face cards are 10. If you choose to stand, your total
should be more than the dealer'
,
text_color='#000000')],
[sg.Button('Start!')]]
window = sg.Window('Welcome', background_color = '#FFFFFF').Layout(welcome)
window.read()
window.close()
first = [ [sg.Text('The dealer has dealt the cards:', font=('Times New Roman'))],
[sg.Text(f'Your two starting cards are {random1} and {random2}')],
[sg.Text(f'Dealer shows his faced up card: {dealer1}')],
[sg.Button('Hit'), sg.Button('Stand')] ]
window = sg.Window('First set', first)
event, values = window.Read()
print(event)
This is the very long error i get:
Traceback (most recent call last):
File "C:\Users\j\Desktop\Applied Computing\Python\blackjack.py", line 32, in <module>
event, values = window.Read()
File "C:\Users\j\AppData\Roaming\Python\Python39\site-packages\PySimpleGUI\PySimpleGUI.py", line 8328, in read
results = self._read(timeout=timeout, timeout_key=timeout_key)
File "C:\Users\j\AppData\Roaming\Python\Python39\site-packages\PySimpleGUI\PySimpleGUI.py", line 8394, in _read
self._Show()
File "C:\Users\j\AppData\Roaming\Python\Python39\site-packages\PySimpleGUI\PySimpleGUI.py", line 8155, in _Show
StartupTK(self)
File "C:\Users\j\AppData\Roaming\Python\Python39\site-packages\PySimpleGUI\PySimpleGUI.py", line 13996, in StartupTK
_convert_window_to_tk(window)
File "C:\Users\j\AppData\Roaming\Python\Python39\site-packages\PySimpleGUI\PySimpleGUI.py", line 13868, in _convert_window_to_tk
PackFormIntoFrame(window, master, window)
File "C:\Users\j\AppData\Roaming\Python\Python39\site-packages\PySimpleGUI\PySimpleGUI.py", line 12403, in PackFormIntoFrame
tktext_label = element.Widget = tk.Label(tk_row_frame, textvariable=stringvar, width=width,
File "C:\Users\j\AppData\Local\Programs\Python\Python39\lib\tkinter\__init__.py", line 3148, in __init__
Widget.__init__(self, master, 'label', cnf, kw)
File "C:\Users\j\AppData\Local\Programs\Python\Python39\lib\tkinter\__init__.py", line 2572, in __init__
self.tk.call(
_tkinter.TclError: expected integer but got "New"