我正在为我的应用程序构建GUI,并尝试从文件对话框加载图像。 有人有什么建议吗?这是我的第一个Kivy应用程序,有时我不能完全理解文档。我尝试了多种方法,得到的最好结果是屏幕左下角有一个图像。你知道吗
我尝试了Placing an image in the middle of the label in Kivy的解决方案,但没有解决我的问题。你知道吗
我的.kv文件的一部分:
<RunDemoScreen>:
GridLayout:
rows: 3
cols: 2
Button:
text:"Test"
Button:
text:"File"
on_press: root.file_dialog()
Button:
text: 'Back'
on_release: root.manager.current = 'menu'
python代码的一部分:
class RunDemoScreen(Screen):
def file_dialog(self):
Tk().withdraw()
self.filename = askopenfilename()
print(self.filename)
此代码中的所有内容都正常工作。你知道吗
您需要创建一个图像小部件,然后将图像源更改为self.filename文件名使用您要分配给它的id的变量
在您的.kv中:
在您的.py中:
相关问题 更多 >
编程相关推荐