导言
你好,今天本文将讨论如何在python中创建漂亮的UI应用程序。我知道这听起来有点奇怪,因为我个人觉得标准Tkinter库不足以开发出令人惊奇的UI。今天,我们将介绍4种在python中创建现代应用程序的不同方法,因此,让我们开始,
以前
后
1.使用鳗鱼
我们列表中的第一个方法是针对那些了解HTML&CSS的开发人员(如果您不知道,那么我也强烈推荐它),并提供javascript的基础知识。
它怎麽工作?
基本上,您将使用HTML和CSS开发前端,并用python编写计算或后端部分。ND鳗鱼充当python和javascript之间的桥梁,并传递数据。
安装
pip install Eel
目录结构
└── Folder
├── templates
| ├── index.html
| ├── main.js
| └── style.css
└── main.py
猫主
import eel
# name of folder where the html, css, js, image files are located
eel.init('templates')
@eel.expose
def demo(x):
return x**2
# 1000 is width of window and 600 is the height
eel.start('index.html', size=(1000, 600))
CAT main.js
function compute() {
var data = document.getElementById("data").value
eel.demo(data)(setValue) // call the demo function which we have created in the main.py file
}
function setValue(res) {
document.getElementById("abc").src = res
}
CAT index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>sample</title>
<link href="style.css" rel="stylesheet">
<script type="text/javascript" src="/eel.js"></script
<script type="text/javascript" src="main.js"></script>
</head>
<body>
<!--
have to call compute() from here for example when user clicks any button or something like that.
-->
</body>
</html>
GitHub参考资料
<https://github.com/ChrisKnott/Eel>
2.Figma和Python
好吧,你一定在想Figma和python之间的组合是什么?Figma是一个UI开发工具,不是用python编写的库.嗯!我知道你是对的,但让我们继续读这篇文章吧。
安装
pip install tkdesigner
它是如何工作的
用户只需要使用Figma设计一个接口,然后将Figma文件URL和API令牌粘贴到TkinterDesigner中。TkinterDesigner将自动生成在Tkinter中创建GUI所需的所有代码和图像。
For complete procedure do watch [this](https://www.youtube.com/watch?v=mFjE2-rbpm8&t=66s&ab_channel=Parthjadhav) video on youtube from Parth Jadhav
GitHub参考资料
https://github.com/ParthJadhav/Tkinter-Designer
3.Pywebview
Pywebview是一个轻量级的跨平台包装器,它支持在自己的原生GUI窗口中显示HTML内容的webview组件。Pywebview是由罗曼·西罗科夫 .
安装
pip install pywebview
样本代码
import webview
if __name__ == '__main__':
window = webview.create_window('Load HTML Example', 'index.html')
webview.start(window)
GitHub参考资料
https://github.com/r0x0r/pywebview/
4.PyQT5
PyQt是在python中开发现代平台GUI的一个很好的库。您可以用python编写代码来创建应用程序,这可能有点困难,但由于我们正在讨论最简单的方法,您甚至可以使用称为PyQt5Designer的拖放生成器来创建GUI。通过生成一个.ui文件(即拖放程序)来构建应用程序是一种很好的方法,然后您可以将这个.ui文件转换为.py文件。
安装
pip install PyQt5Designer
步骤
安装后,设计器将安装在您的系统中。简单键入designer在您的命令提示符和设计器.exe将弹出。它会看起来像这样
现在,您可以在画布中拖放元素。在设计应用程序之后,只需将其导出为.ui文件即可。稍后,您可以将这个.ui文件转换为.py文件,
pyuic5 -x [NAME_OF_UI_FILE].ui [NAME_OF_PY_FILE].py
结语
原文 Https://dev.to/yash_makan/4-ways-to-create-modern-gui-in-python-in-easiest-way-possible-5e0e
本文暂时没有评论,来添加一个吧(●'◡'●)