Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

按照教程运行报错了 #1

Open
CharlesJames13586 opened this issue Dec 11, 2024 · 2 comments
Open

按照教程运行报错了 #1

CharlesJames13586 opened this issue Dec 11, 2024 · 2 comments

Comments

@CharlesJames13586
Copy link

(venv)xxxx@MacBook-Pro-3 HandwritingGenerator % python main.py
Traceback (most recent call last):
  File "/Users/xxxx/Desktop/wsp/python/HandwritingGenerator/main.py", line 569, in <module>
    viewer = HandFontWindow()
             ^^^^^^^^^^^^^^^^
  File "/Users/xxxx/Desktop/wsp/python/HandwritingGenerator/main.py", line 133, in __init__
    self.initUI()
  File "/Users/xxxx/Desktop/wsp/python/HandwritingGenerator/main.py", line 155, in initUI
    self.updateView()
  File "/Users/xxxx/Desktop/wsp/python/HandwritingGenerator/main.py", line 354, in updateView
    self.view.addTextItem(text=text_tmp, 
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/xxxx/Desktop/wsp/python/HandwritingGenerator/main.py", line 508, in addTextItem
    font_family = QFontDatabase.applicationFontFamilies(font_id)[0]
                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^
IndexError: list index out of range
@CharlesJames13586
Copy link
Author

作者你好,按照教程运行的python main.py时报错了,麻烦了

@CharlesJames13586
Copy link
Author

        # 加载本地字体文件,设置字体大小
        font_id = QFontDatabase.addApplicationFont(font_path)
        if font_id == -1:
            print("Failed to load font")
            return
        font_family = QFontDatabase.applicationFontFamilies(font_id)[0]

加了检测代码,提前退出相关函数可以正常运行了。
用大模型搞定了,我自己还没有细看代码

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant