Ubuntu Linux安装PyQt5并配置Qt Designer

PyQt5

PyQt5让我们可以使用python语言创建图形应用程序

Qt Designer提供可视化的方式,让我们可以通过拖动各种组件进行图形应用程序的设计

不管是在Windows还是Linux,只要安装了Qt Designer就可以开始进行图形化应用程序的设计,产生的文件是.ui

在很多教程中,介绍如何在pycharm和vscode中进行配置来使用Qt Designer,其实本质上还是用过软件来执行命令调用Qt Designer的可执行文件而已,与你直接打开***\\site-packages\\pyqt5-tools\\designer.exe(Windows)和终端执行cd /usr/lib/x86_64-linux-gnu/qt5/bin/ && ./designer(Ubuntu Linux)并无不同,前提是已经安装好了pyqt5-tools

pyuic5则是通过pyuic5的命令将.ui的文件转化为.py文件

pyuic5 helloworld.ui -o helloworld.py

总的来说就是Qt Designer通过拖拽的方式放置控件,并实时查看控件效果进行快速UI设计,最终生成.ui文件(实质上是XML格式的文件),.ui文件可以通过pyuic工具转换成.py文件。

Windows:PyQt5安装与PyCharm配置Qt Designer

Linux:

创建独立环境

创建conda环境

conda create -n pyqt python=3.8

安装pyqt5

pip install pyqt5

查看版本

确认版本也是非常重要的,因为pyqt5很强调版本兼容问题,说明在这方面确实可能遇到问题,要是代码换了个环境,突然不能正常使用,先考虑是否版本兼容问题

通过pyuic5将ui文件重新生成python文件也许可以解决

pip show pyqt5
# Name: PyQt5
# Version: 5.15.2

安装图形界面Qt Designer

sudo apt-get install qttools5-dev-tools
sudo apt-get install qttools5-dev

安装之后可执行文件designer在/usr/lib/x86_64-linux-gnu/qt5/bin/

cd /usr/lib/x86_64-linux-gnu/qt5/bin/ 
./designer

执行即可打开Qt Designer,编辑之后File > Save As保存为.ui文件

将ui转为python代码

pyuic5 path/to/helloworld.ui -o path/to/helloworld.py

上面的命令生成的代码只是一些定义的函数,并没有调用,执行之后并不会有任何界面显示,需要在另外的python文件中进行import之后调用;
如果想要在单独一个文件中执行并显示图形结果,可以使用

pyuic5 -x path/to/helloworld.ui -o path/to/helloworld.py

添加参数-x--execute,生成的Python代码包括少量其他代码,这些代码在作为独立应用程序执行时会创建并显示GUI。

pycharm 配置

PyQt5安装与PyCharm配置Qt Designer

vs code配置

添加pyqt integration插件

File > Preferences > Settings,搜索pyqt integration

找到Pyqt-integration > Qtdesigner:path,里面输入designer的路径/usr/lib/x86_64-linux-gnu/qt5/bin/designer
在这里插入图片描述
设置好之后在vscode编辑器的左侧文件目录栏空白位置邮件,选择PYQT:New Form即可打开Qt Designer

编辑保存.ui之后,右键该文件,选择PYQT:Compile Form,即可将.ui转为.py

生成的py文件里提示,不要手动去修改该文件,因为当再次执行pyuic5之后,所有的修改都会被覆盖,所以如果要运行这个py文件,就新建一个独立的py文件去import,调用就好了

# main.py
import sys
from PyQt5.QtWidgets import QApplication, QMainWindow
import helloworld  # 生成的文件

if __name__ == '__main__': 
    app = QApplication(sys.argv) 
    MainWindow = QMainWindow() 
    ui = Ui_MainWindow() 
    ui.setupUi(MainWindow) 
    MainWindow.show() 
    sys.exit(app.exec_())

如果要每次执行pyuic5就生成单独可以执行的文件,就在Pyqt-integration > Pyuic > Compile: Add Options添加-x参数

### 回答1: 在 TURBO C 2.0 中,您可以使用 biosdisk() 函数来格式化软盘。 下面是一段代码示例: ``` #include <stdio.h> #include <dos.h> int main() { // 定义扇区的大小 unsigned int sector_size[3] = {512, 512, 1024}; // 定义填充字节 unsigned char fill_char[3] = {0xF6, 0xF6, 0x48}; // 格式化磁道 70 面 0 的前三个扇区 for (int i = 0; i < 3; i++) { int result = biosdisk(2, 0, 70, 0, i + 1, 1, sector_size[i], fill_char[i]); if (result != 0) { printf("格式化扇区 %d 失败,返回码: %d\n", i + 1, result); } } return 0; } ``` 请注意,在使用 biosdisk() 函数之前,需要包含 dos.h 头文件。 希望这能帮到您! ### 回答2: 使用TURBO C 2.0语言,可以通过以下代码格式化软盘的70磁道0面,分别格式化3个扇区,大小分别为512字节、512字节和1024字节。其中,前两个扇区使用F6填充,第三个扇区使用48填充。 ```c #include<stdlib.h> #include<stdio.h> #include<dos.h> void formatFloppyDisk(){ union REGS regs; regs.h.ah = 0x0;// To format a floppy disk, we set AH=0 regs.h.dl = 0;// Drive number (0=A, 1=B, etc.) regs.x.cx = 0;// Track number to format regs.h.dh = 0;// Head number regs.h.al = 0;// Sector size (0=default, 1=512 bytes, 2=1024 bytes, 3=2048 bytes etc.) int FILL_BYTE = 0;// The byte value to fill the sectors with during formatting int NUM_SECTORS = 3;// Number of sectors to format // To format 70th track 0th head regs.x.ax = 0x1301; // 0x13 = Reset disk system, 01H = Reset only specified drive int86(0x13, &regs, &regs); // BIOS interrupt to reset disk system for (int i=0; i<NUM_SECTORS; i++){ regs.x.ax = 0x3101; // 0x31 = Write Format, 01H = Format only current track regs.x.bx = 0x0001; // 0x00 = Drive A:, 01H = Head 1, 0 = Generate ID Field depending on the disk in the drive 1 = Keep the ID Field all zeros regs.x.cx = 0x0170; // Track number=70(0-79 range) regs.h.dh = 0x00; // Head number=0 or 1 regs.h.al = 0x02; // Control byte=always zero regs.x.dx = i+1; // Sector number starting from 1 regs.x.si = 0x0000; // segment and offset of read/write buffer regs.x.di = 0x0000; // segment and offset of result if(i == 2){ FILL_BYTE = 0x48; // Fill the third sector with 48 regs.x.ax = 0x3102; // 0x31 = Write Format, 02H = Format sequential tracks immediately following the one being formatted }else{ FILL_BYTE = 0xF6; // Fill the first two sectors with F6 } regs.h.ah = FILL_BYTE; // Fill the sector with specified byte int86(0x13, &regs, &regs); // BIOS interrupt to format the specified sector } } int main(){ formatFloppyDisk(); return 0; } ``` 上述代码使用了INT 0x13,即BIOS中断服务例程,来执行软盘格式化操作。通过设置寄存器的不同参数,可以指定要格式化的磁道、面、扇区大小和填充字节。在这个例子中,我们格式化了软盘70磁道0面的3个扇区,前两个扇区使用F6填充,第三个扇区使用48填充。
评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

斌zz

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值