我是一个编程新手,我正在寻找一些关于如何在没有Tkinter库的情况下用python制作可点击图像的代码或教程,但我没有找到任何人。无论如何,我正在尝试在一个游戏中制作一个音乐播放器,在这个游戏中,你必须猜测歌曲的名称,比如一段简短的旋律,但我需要点击"play.png“来播放旋律,而我不知道怎么做。有人能帮我吗?非常感谢
发布于 2021-05-26 19:46:56
正如评论中提到的,除了Tkinter之外,还有几个GUI框架或工具包可用。
下面是一个使用viaduc并调整其helloworld.py的简单示例。
#!/usr/bin/env python3
from viaduc import Viaduc
class Presentation(Viaduc.Presentation):
title = 'audio player'
width = 496
height = 336
html = '''
<!DOCTYPE html>
<html lang="en">
<head>
{{bootstrap_meta}}
{{bootstrap_css}}
<title>{{title}}</title>
</head>
<body>
{{frameless_close_button}}
<div class="jumbotron">
<h1>{{title}}</h1>
<p class="lead">Welcome to <em>Viaduc</em>, the simplest way of creating a GUI in python.</p>
</div>
<div class="mx-auto" style="width: 90%;">
<audio src="https://samplelib.com/lib/preview/mp3/sample-6s.mp3" controls="" controlslist="nodownload" style="width:100%"></audio>
</div>
{{bootstrap_js}}
</body>
</html>
'''
if __name__ == '__main__':
Viaduc(presentation=Presentation(), args=['', '--frameless'])
它会产生
并且可以播放音频样本。
https://stackoverflow.com/questions/67709959
复制