吾爱破解 - 52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 1618|回复: 18
上一主题 下一主题
收起左侧

[Python 原创] 用PS设计和wxpython做出漂亮的界面实例

  [复制链接]
跳转到指定楼层
楼主
machuhai 发表于 2024-10-25 15:40 回帖奖励
本帖最后由 machuhai 于 2024-10-25 15:46 编辑

思路 先用ps设计好效果图,裁剪好用wxpython的wx.BoxSizer排版,就能做出漂亮的界面

只做了个界面,功能我没写,给有需要的去练习完成。

下面是源码
[Python] 纯文本查看 复制代码
import wx


class MyPanel(wx.Panel):
    def __init__(self, parent, id):
        wx.Panel.__init__(self, parent, id)


        VERTICAL = wx.BoxSizer(wx.VERTICAL)
        image_file = '01.gif'
        to_bmp_image = wx.Image(image_file, wx.BITMAP_TYPE_ANY).ConvertToBitmap()
        self.bitmap = wx.StaticBitmap(self, -1, to_bmp_image, (0, 0))
        VERTICAL.Add(self.bitmap, 0, wx.ALL | wx.LEFT, 0)


        HORIZONTAL = wx.BoxSizer(wx.HORIZONTAL)
        image = wx.Image('11.gif', wx.BITMAP_TYPE_ANY)
        bitmap1 = wx.Bitmap(image)
        # 创建位图按钮
        self.button11 = wx.BitmapButton(self, id=wx.ID_ANY, bitmap=bitmap1,
                                       size=(image.GetWidth(), image.GetHeight()))
        image = wx.Image('12.gif', wx.BITMAP_TYPE_ANY)
        bitmap2 = wx.Bitmap(image)
        # 创建位图按钮
        self.button12 = wx.BitmapButton(self, id=wx.ID_ANY, bitmap=bitmap2,
                                       size=(image.GetWidth(), image.GetHeight()))
        image = wx.Image('13.gif', wx.BITMAP_TYPE_ANY)
        bitmap3 = wx.Bitmap(image)
        self.button13 = wx.BitmapButton(self, id=wx.ID_ANY, bitmap=bitmap3,
                                       size=(image.GetWidth(), image.GetHeight()))
        image = wx.Image('14.gif', wx.BITMAP_TYPE_ANY)
        bitmap4 = wx.Bitmap(image)
        # 创建位图按钮
        self.button14 = wx.BitmapButton(self, id=wx.ID_ANY, bitmap=bitmap4,
                                       size=(image.GetWidth(), image.GetHeight()))
        HORIZONTAL.Add(self.button11, 0, wx.ALL | wx.LEFT, 0)
        HORIZONTAL.Add(self.button12, 0, wx.ALL | wx.LEFT, 0)
        HORIZONTAL.Add(self.button13, 0, wx.ALL | wx.LEFT, 0)
        HORIZONTAL.Add(self.button14, 0, wx.ALL | wx.LEFT, 0)


        HORIZONTAL2 = wx.BoxSizer(wx.HORIZONTAL)
        image = wx.Image('21.gif', wx.BITMAP_TYPE_ANY)
        bitmap1 = wx.Bitmap(image)
        # 创建位图按钮
        self.button21 = wx.BitmapButton(self, id=wx.ID_ANY, bitmap=bitmap1,
                                       size=(image.GetWidth(), image.GetHeight()))
        image = wx.Image('22.gif', wx.BITMAP_TYPE_ANY)
        bitmap2 = wx.Bitmap(image)
        # 创建位图按钮
        self.button22 = wx.BitmapButton(self, id=wx.ID_ANY, bitmap=bitmap2,
                                       size=(image.GetWidth(), image.GetHeight()))
        image = wx.Image('23.gif', wx.BITMAP_TYPE_ANY)
        bitmap3 = wx.Bitmap(image)
        # 创建位图按钮
        self.button23 = wx.BitmapButton(self, id=wx.ID_ANY, bitmap=bitmap3,
                                       size=(image.GetWidth(), image.GetHeight()))
        image = wx.Image('24.gif', wx.BITMAP_TYPE_ANY)
        bitmap4 = wx.Bitmap(image)
        # 创建位图按钮
        self.button24 = wx.BitmapButton(self, id=wx.ID_ANY, bitmap=bitmap4,
                                       size=(image.GetWidth(), image.GetHeight()))
        HORIZONTAL2.Add(self.button21, 0, wx.ALL | wx.LEFT, 0)
        HORIZONTAL2.Add(self.button22, 0, wx.ALL | wx.LEFT, 0)
        HORIZONTAL2.Add(self.button23, 0, wx.ALL | wx.LEFT, 0)
        HORIZONTAL2.Add(self.button24, 0, wx.ALL | wx.LEFT, 0)


        HORIZONTAL3 = wx.BoxSizer(wx.HORIZONTAL)
        image = wx.Image('31.gif', wx.BITMAP_TYPE_ANY)
        bitmap1 = wx.Bitmap(image)
        # 创建位图按钮
        self.button31 = wx.BitmapButton(self, id=wx.ID_ANY, bitmap=bitmap1,
                                        size=(image.GetWidth(), image.GetHeight()))
        image = wx.Image('32.gif', wx.BITMAP_TYPE_ANY)
        bitmap2 = wx.Bitmap(image)
        # 创建位图按钮
        self.button32 = wx.BitmapButton(self, id=wx.ID_ANY, bitmap=bitmap2,
                                        size=(image.GetWidth(), image.GetHeight()))
        image = wx.Image('33.gif', wx.BITMAP_TYPE_ANY)
        bitmap3 = wx.Bitmap(image)
        # 创建位图按钮
        self.button33 = wx.BitmapButton(self, id=wx.ID_ANY, bitmap=bitmap3,
                                        size=(image.GetWidth(), image.GetHeight()))
        image = wx.Image('34.gif', wx.BITMAP_TYPE_ANY)
        bitmap4 = wx.Bitmap(image)
        # 创建位图按钮
        self.button34 = wx.BitmapButton(self, id=wx.ID_ANY, bitmap=bitmap4,
                                        size=(image.GetWidth(), image.GetHeight()))
        HORIZONTAL3.Add(self.button31, 0, wx.ALL | wx.LEFT, 0)
        HORIZONTAL3.Add(self.button32, 0, wx.ALL | wx.LEFT, 0)
        HORIZONTAL3.Add(self.button33, 0, wx.ALL | wx.LEFT, 0)
        HORIZONTAL3.Add(self.button34, 0, wx.ALL | wx.LEFT, 0)


        HORIZONTAL4 = wx.BoxSizer(wx.HORIZONTAL)
        image = wx.Image('41.gif', wx.BITMAP_TYPE_ANY)
        bitmap1 = wx.Bitmap(image)
        # 创建位图按钮
        self.button41 = wx.BitmapButton(self, id=wx.ID_ANY, bitmap=bitmap1,
                                        size=(image.GetWidth(), image.GetHeight()))
        image = wx.Image('42.gif', wx.BITMAP_TYPE_ANY)
        bitmap2 = wx.Bitmap(image)
        # 创建位图按钮
        self.button42 = wx.BitmapButton(self, id=wx.ID_ANY, bitmap=bitmap2,
                                        size=(image.GetWidth(), image.GetHeight()))
        image = wx.Image('43.gif', wx.BITMAP_TYPE_ANY)
        bitmap3 = wx.Bitmap(image)
        # 创建位图按钮
        self.button43 = wx.BitmapButton(self, id=wx.ID_ANY, bitmap=bitmap3,
                                        size=(image.GetWidth(), image.GetHeight()))
        image = wx.Image('44.gif', wx.BITMAP_TYPE_ANY)
        bitmap4 = wx.Bitmap(image)
        # 创建位图按钮
        self.button44 = wx.BitmapButton(self, id=wx.ID_ANY, bitmap=bitmap4,
                                        size=(image.GetWidth(), image.GetHeight()))
        HORIZONTAL4.Add(self.button41, 0, wx.ALL | wx.LEFT, 0)
        HORIZONTAL4.Add(self.button42, 0, wx.ALL | wx.LEFT, 0)
        HORIZONTAL4.Add(self.button43, 0, wx.ALL | wx.LEFT, 0)
        HORIZONTAL4.Add(self.button44, 0, wx.ALL | wx.LEFT, 0)


        HORIZONTAL5 = wx.BoxSizer(wx.HORIZONTAL)
        image = wx.Image('51.gif', wx.BITMAP_TYPE_ANY)
        bitmap1 = wx.Bitmap(image)
        # 创建位图按钮
        self.button51 = wx.BitmapButton(self, id=wx.ID_ANY, bitmap=bitmap1,
                                        size=(image.GetWidth(), image.GetHeight()))
        image = wx.Image('52.gif', wx.BITMAP_TYPE_ANY)
        bitmap2 = wx.Bitmap(image)
        # 创建位图按钮
        self.button52 = wx.BitmapButton(self, id=wx.ID_ANY, bitmap=bitmap2,
                                        size=(image.GetWidth(), image.GetHeight()))
        image = wx.Image('53.gif', wx.BITMAP_TYPE_ANY)
        bitmap3 = wx.Bitmap(image)
        # 创建位图按钮
        self.button53 = wx.BitmapButton(self, id=wx.ID_ANY, bitmap=bitmap3,
                                        size=(image.GetWidth(), image.GetHeight()))
        image = wx.Image('54.gif', wx.BITMAP_TYPE_ANY)
        bitmap4 = wx.Bitmap(image)
        # 创建位图按钮
        self.button54 = wx.BitmapButton(self, id=wx.ID_ANY, bitmap=bitmap4,
                                        size=(image.GetWidth(), image.GetHeight()))
        HORIZONTAL5.Add(self.button51, 0, wx.ALL | wx.LEFT, 0)
        HORIZONTAL5.Add(self.button52, 0, wx.ALL | wx.LEFT, 0)
        HORIZONTAL5.Add(self.button53, 0, wx.ALL | wx.LEFT, 0)
        HORIZONTAL5.Add(self.button54, 0, wx.ALL | wx.LEFT, 0)



        VERTICAL.Add(HORIZONTAL, 0, wx.ALL | wx.LEFT, 0)
        VERTICAL.Add(HORIZONTAL2, 0, wx.ALL | wx.LEFT, 0)
        VERTICAL.Add(HORIZONTAL3, 0, wx.ALL | wx.LEFT, 0)
        VERTICAL.Add(HORIZONTAL4, 0, wx.ALL | wx.LEFT, 0)
        VERTICAL.Add(HORIZONTAL5, 0, wx.ALL | wx.LEFT, 0)

        self.SetSizer(VERTICAL)


        self.编辑框1 = wx.TextCtrl(self.bitmap, size=(457, 150), pos=(20, 22), value='', name='text',
                                   style=wx.TE_MULTILINE)
        self.编辑框1.SetBackgroundColour('light grey')
        self.编辑框1.SetFont(wx.Font(26, wx.ROMAN, wx.NORMAL, wx.BOLD))

        self.button11.Bind(wx.EVT_BUTTON, self.ac)
        self.button14.Bind(wx.EVT_BUTTON, self.加)

        self.button21.Bind(wx.EVT_BUTTON, self.一)
        self.button22.Bind(wx.EVT_BUTTON, self.二)
        self.button23.Bind(wx.EVT_BUTTON, self.三)
        self.button24.Bind(wx.EVT_BUTTON, self.减)

        self.button31.Bind(wx.EVT_BUTTON, self.四)
        self.button32.Bind(wx.EVT_BUTTON, self.五)
        self.button33.Bind(wx.EVT_BUTTON, self.六)
        self.button34.Bind(wx.EVT_BUTTON, self.乘)

        self.button41.Bind(wx.EVT_BUTTON, self.七)
        self.button42.Bind(wx.EVT_BUTTON, self.八)
        self.button43.Bind(wx.EVT_BUTTON, self.九)
        self.button44.Bind(wx.EVT_BUTTON, self.除)

        self.button52.Bind(wx.EVT_BUTTON, self.零)
        self.button53.Bind(wx.EVT_BUTTON, self.点)
        self.button54.Bind(wx.EVT_BUTTON, self.等)



    def ac(self,event):
        self.编辑框1.Clear()

    def 加(self,event):
        self.编辑框1.AppendText('+')

    def 减(self,event):
        self.编辑框1.AppendText('-')

    def 乘(self,event):
        self.编辑框1.AppendText('x')

    def 除(self,event):
        self.编辑框1.AppendText('÷')

    def 点(self,event):
        self.编辑框1.AppendText('.')

    def 等(self,event):
        self.编辑框1.AppendText('=')

    def 一(self,event):
        self.编辑框1.AppendText('1')

    def 二(self,event):
        self.编辑框1.AppendText('2')

    def 三(self,event):
        self.编辑框1.AppendText('3')

    def 四(self,event):
        self.编辑框1.AppendText('4')

    def 五(self,event):
        self.编辑框1.AppendText('5')

    def 六(self,event):
        self.编辑框1.AppendText('6')

    def 七(self,event):
        self.编辑框1.AppendText('7')

    def 八(self,event):
        self.编辑框1.AppendText('8')

    def 九(self,event):
        self.编辑框1.AppendText('9')

    def 零(self,event):
        self.编辑框1.AppendText('0')


if __name__ == '__main__':
    app = wx.App()
    frame = wx.Frame(None, -1, '计算器v0.1', size=(507, 632))
    frame.SetIcon(wx.Icon('ioc.jpg'))
    my_panel = MyPanel(frame, -1)
    frame.Show()
    app.MainLoop()


源码和素材

images.zip (108.36 KB, 下载次数: 26)

免费评分

参与人数 5吾爱币 +11 热心值 +3 收起 理由
苏紫方璇 + 7 + 1 欢迎分析讨论交流,吾爱破解论坛有你更精彩!
zhangt729 + 1 + 1 谢谢@Thanks!
快乐的小驹 + 1 谢谢@Thanks!
apull + 1 + 1 谢谢@Thanks!
shenquanwusheng + 1 热心回复!

查看全部评分

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

推荐
bachelor66 发表于 2024-10-25 17:17
这界面看着很漂亮啊,学习一下                                       
推荐
桓先生 发表于 2024-10-26 09:51
个人愚见,色彩太多了,显得杂乱。小数点所在的框没有对齐,不协调。数字太大了 和阴影重合了,比较割裂。
沙发
chh322 发表于 2024-10-25 15:54
3#
abpyu 发表于 2024-10-25 16:30
这个厉害这个厉害
4#
cnmingxing 发表于 2024-10-25 16:42
感谢分享
5#
tiantou 发表于 2024-10-25 16:56
学习了,感谢分享
7#
青蛙考拉 发表于 2024-10-25 19:36
一点都不好看,花里胡哨
8#
yang0888 发表于 2024-10-25 21:54
这个厉害了
9#
龍謹 发表于 2024-10-26 06:57
学无止尽,向楼主和坛友们学习。
10#
apull 发表于 2024-10-26 07:35
这个厉害了,学习下
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则

返回列表

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-11-1 09:40

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表