使用uic在Python中将.ui文件转换为.py文件时出错
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了使用uic在Python中将.ui文件转换为.py文件时出错,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1818字,纯文字阅读大概需要3分钟。
内容图文
![使用uic在Python中将.ui文件转换为.py文件时出错](/upload/InfoBanner/zyjiaocheng/683/c6bbd6c45aac4bc784cd93910d1c706d.jpg)
我试图用python编写一个程序,该程序会将同一文件夹(在Qt Designer中创建)中的.ui文件转换为.py文件.这是这个极其基础的程序的代码:
# -*- coding: utf-8 -*-
from PyQt4 import uic
with open('exampleinterface.py', 'w') as fout:
uic.compileUi('exampleinterface.ui', fout)
它给出了以下错误(缩短了长路径名):
Traceback (most recent call last):
File “”, line 1, in
File “…\Python32_3.5\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py”, line 699, in runfile
execfile(filename, namespace)File “…\Python32_3.5\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py”, line 88, in execfile
exec(compile(open(filename, ‘rb’).read(), filename, ‘exec’), namespace)
File “…/Documents/Python/UiToPy/minimalconvert.py”, line 11, in
uic.compileUi(‘exampleinterface.ui’, fout)File “…\Python32_3.5\lib\site-packages\PyQt4\uic__init__.py”, line 173, in compileUi
winfo = compiler.UICompiler().compileUi(uifile, pyfile, from_imports, resource_suffix)File “…\Python32_3.5\lib\site-packages\PyQt4\uic\Compiler\compiler.py”, line 140, in compileUi
w = self.parse(input_stream, resource_suffix)File “…\Python32_3.5\lib\site-packages\PyQt4\uic\uiparser.py”, line 974, in parse
document = parse(filename)File “…\Python32_3.5\lib\xml\etree\ElementTree.py”, line 1182, in parse
tree.parse(source, parser)File “…\Python32_3.5\lib\xml\etree\ElementTree.py”, line 594, in parse
self._root = parser._parse_whole(source)
xml.etree.ElementTree.ParseError: not well-formed (invalid token): line 1, column 1
谁能告诉我为什么这不起作用,以及是否有解决方案?
注意:我知道还有其他方法可以将.ui文件转换为.py文件,但是我正在寻找一种可以轻松集成到python程序中而无需调用外部文件的方法.
解决方法:
出现此错误是因为我的.ui文件未保存在我最近所做的更改中.文件名在文件名中显示星号(*).一旦我保存了更改文件,就可以将其转换为.py文件.
内容总结
以上是互联网集市为您收集整理的使用uic在Python中将.ui文件转换为.py文件时出错全部内容,希望文章能够帮你解决使用uic在Python中将.ui文件转换为.py文件时出错所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。