【发布时间】:2021-08-11 10:34:27
【问题描述】:
我是编程新手,刚开始使用 PySimpleGUI 尝试二十一点游戏。我不知道为什么我在 line event,values = window.Read() 上得到错误。任何帮助表示赞赏。
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)
这是我得到的很长的错误:
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"
【问题讨论】:
-
你能发布错误信息吗?
-
是的,我收到一个很长的错误。由于字符限制,无法在此处发布全部内容:我将其添加到实际帖子@CoolCoder
标签: python events window display pysimplegui