用PS设计和wxpython做出漂亮的界面实例
本帖最后由 machuhai 于 2024-10-25 15:46 编辑思路 先用ps设计好效果图,裁剪好用wxpython的wx.BoxSizer排版,就能做出漂亮的界面
只做了个界面,功能我没写,给有需要的去练习完成。
下面是源码
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()
源码和素材
这界面看着很漂亮啊,学习一下 个人愚见,色彩太多了,显得杂乱。小数点所在的框没有对齐,不协调。数字太大了 和阴影重合了,比较割裂。 是个不错的思路 学习了 这个厉害这个厉害:lol 感谢分享 学习了,感谢分享 一点都不好看,花里胡哨{:1_911:} 这个厉害了 学无止尽,向楼主和坛友们学习。 这个厉害了,学习下
页:
[1]
2