效果展示
代码参考
#!/usr/bin/python# -*- coding:utf-8 -*-import sysfrom pyqt5 import qtwidgets, qtcorefrom pyqt5.qtwidgets import * class qt_view(qwidget): def __init__(lf): super(qt_view, lf).__init__() lf.resize(600, 250) lf.twindowtitle("圆点选择") lf.radiobutton_1 = qtwidgets.qradiobutton(lf) lf.radiobutton_1.tgeometry(qtcore.qrect(230, 100, 89, 16)) lf.radiobutton_1.tstylesheet("font-family:微软雅黑; color:black;") lf.radiobutton_1.tobjectname("radiobutton_1") lf.radiobutton_2 = qtwidgets.qradiobutton(lf) lf.radiobutton_2.tgeometry(qtcore.qrect(310, 100, 89, 16)) lf.radiobutton_2.tstylesheet("font-family:微软雅黑; color:black;") lf.radiobutton_2.tobjectname("radiobutton_2") translate = qtcore.qcoreapplication.translate lf.radiobutton_1.ttext(translate("form", "选项1")) lf.radiobutton_2.ttext(translate("form", "选项2")) if __name__ == '__main__': app = qtwidgets.qapplication(sys.argv) my = qt_view() my.show() app.exec_()
效果展示
代码参考
import sysfrom pyqt5 import qtwidgets, qtcorefrom pyqt5.qtwidgets import * class qt_view(qwidget): def __init__(lf): super(qt_view, lf).__init__() lf.resize(600, 250) lf.twindowtitle("圆灰按钮") button_open_img = qpushbutton(lf) button_open_img.ttext("打开图片") button_open_img.move(250, 100) button_open_img.tfixedsize(150, 50) button_open_img.tstylesheet("qpushbutton{\n" " background:orange;\n" " color:white;\n" " box-shadow: 1px 1px 3px;font-size:18px;border-radius: 24px;font-family: 微软雅黑;\n" "}\n" "qpushbutton:presd{\n" " background:black;\n" "}") if __name__ == '__main__': app = qtwidgets.qapplication(sys.argv) my = qt_view() my.show() app.exec_()
效果展示
代码参考
import sysfrom pyqt5 import qtwidgets, qtcorefrom pyqt5.qtwidgets import * class qt_view(qwidget): def __init__(lf): super(qt_view, lf).__init__() print("关闭弹窗") result = qmessagebox.question(lf, "注意!", "您真的要关闭吗?", qmessagebox.yes | qmessagebox.no, qmessagebox.no) if result == qmessagebox.yes: qmessagebox.information(lf, "消息", "谢谢使用陪着你慢慢长大!") quit() el: qmessagebox.information(lf, "消息", "正在返回...") quit() if __name__ == '__main__': app = qtwidgets.qapplication(sys.argv) my = qt_view() my.show() app.exec_()
效果展示
代码参考
from pyqt5 import qtwidgetsimport sys class ui_dialog(object): def tupui(lf, dialog): dialog.tobjectname("dialog") dialog.resize(600, 320) class dialog(qtwidgets.qmainwindow): def cloevent(lf, event): reply = qtwidgets.qmessagebox.question(lf, '本程序', "是否要退出程序?", qtwidgets.qmessagebox.yes | qtwidgets狂人日记赏析.qmessagebox.no, qtwidgets.qmessagebox.no) if reply == qtwidgets.qmessagebox.yes: event.accept() el: event.ignore() if __name__ == '__main__': app = qtwidgets.qapplication(sys.argv) dialog = dialog() ui = ui_dialog() ui.tupui(dialog) dialog.show() sys.exit(app.exec_())
效果展示
代码参考
import sysfrom pyqt5 import qtwidgets, qtcorefrom pyqt5.qtwidgets import *from pyqt5.qtcore import * class gui_view(qwidget): def __init__(lf): super(gui_view, lf).__init__() lf.resize(500, 350) lf.twindowflags(qt.framelesswindowhint) # 去边框 # # lf.tattribute(qt.wa_translucentbackground) # 设置窗口背景透明 button_red = qpushbutton(lf) button_red.move(20, 20) button_red.tfixedsize(20, 20) button_red.tstylesheet("qpushbutton{\n" " background:#ce0000;\n" " color:white;\n" " box-shadow: 1px 1px 3px;border-radius: 10px;\n" "}\n" "qpushbutton:hover{ \n" " background:red;\n" "}\n" "qpushbutton:presd{\n" " border: 1px solid #3c3c3c!important;\n" " background:black;\n" "}") button_red.clicked.connect(lf.quit_button) button_orange = qpushbutton(lf) button_orange.move(50, 20) button_orange.tfixedsize(20, 20) button_orange.tstylesheet("qpushbutton{\n" " background:orange;\n" " color:white;\n" " box-shadow: 1px 1px 3px;border-radius: 10px;\n" "}\n" "qpushbutton:hover{ \n" " background:yellow;\n" "}\n" "qpushbutton:presd{\n" " border: 1px solid #3c3c3c!important;\n" " background:black;\n" "}") button_green = qpushbutton(lf) button_green.move(80, 20) button_green.tfixedsize(20, 20) button_green.tstylesheet("qpushbutton{\n" " background:green;\n" " color:white;\n" " box-shadow: 1px 1px 3px;border-radius: 10px;\n" "}\n" "qpushbutton:hover{ \n" " background:#08bf14;\n" "}\n" "qpushbutton:presd{\n" " border: 1px solid #3c3c3c!important;\n" " background:black;\n" "}") def quit_button(lf): quit() if __name__ == '__main__': app2 = qtwidgets.qapplication(sys.argv) my = gui_view() my.show() app2.exec_()
效果展示
代码参考
import sysfrom pyqt5 import qtwidgets, qtcorefrom pyqt5.qtwidgets import *from pyqt5 import qtgui class gui_view(qwidget): def __init__(lf): super(gui_view, lf).__init__() lf.resize(1200, 750) # lf.tstylesheet("background-image: url(:f:/background.jpg);") lf.twindowtitle("设置背景图片") window_pale = qtgui.qpalette() window_pale落花犹怜逐香尘.tbrush(lf.backgroundrole(), qtgui.qbrush(qtgui.qpixmap("f:/background.jpg"))) lf.tpalette(window_pale) if __name__ == '__main__': app2 = qtwidgets.qapplication(sys.argv) my = gui_view() my.show() app2.exec_()
效果展示
代码参考
import sysfrom pyqt5.qtwidgets import qwidget, qcombobox, qapplication class comboxdemo(qwidget): def __init__(lf): super().__init__() lf.twindowtitle('下拉列表框') lf.resize(700, 400) # 实例化qcombox对象 lf.cb = qcombobox(lf) lf.cb.move(100, 20) # 单个添加条目 lf.cb.additem('选项1') lf.cb.additem('选项2') # 多个添加条目 lf.cb.additems(['选项3', '选项4', '选项5']) lf.cb.currentindexchanged[str].connect(lf.print_value) d滴定度的计算公式ef print_value(lf, value): print(value) if __name__ == '__main__': app = qapplication(sys.argv) comboxdemo = comboxdemo() comboxdemo.show() sys.exit(app.exec_())
效果展示
代码参考
from pyqt5.qtwidgets import qmainwindow, qprogressbar, qapplication, qlabel, qstatusbar, qpushbuttonimport sys class samplebar(qmainwindow): def __init__(lf, parent=none): super(samplebar, lf).__init__(parent) lf.tminimumsize(400, 100) lf.statusbar = qstatusbar() lf.statusbar.tstylesheet('qstatusbar::item {border: none;}') lf.tstatusbar(lf.statusbar) lf.progressbar = qprogressbar() lf.label = qlabel() lf.label.ttext("加载中,请稍后... ") lf.statusbar.addpermanentwidget(lf.label, stretch=2) lf.statusbar.addpermanentwidget(lf.progressbar, stretch=4) lf.progressbar.trange(0, 100) lf.progressbar.tminimum(0) lf.progressbar.tmaximum(0) if __name__ == '__main__': app = qapplication(sys.argv) main = samplebar() main.show() sys.exit(app.exec_())
到此这篇关于如何利用pyqt5美化你的gui界面的文章就介夏季减肥方法绍到这了,更多相关pyqt5美化gui界面内容请搜索www.887551.com以前的文章或继续浏览下面的相关文章希望大家以后多多支持www.887551.com!
本文发布于:2023-04-04 16:33:14,感谢您对本站的认可!
本文链接:https://www.wtabcd.cn/fanwen/zuowen/63eb7e4cfe8b666398d667dde15afae7.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文word下载地址:如何利用PyQt5美化你的GUI界面.doc
本文 PDF 下载地址:如何利用PyQt5美化你的GUI界面.pdf
留言与评论(共有 0 条评论) |