欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

wxpython自定義下拉列表框過程圖解

 更新時間:2020年02月14日 10:14:47   作者:傅延年  
這篇文章主要介紹了wxpython自定義下拉列表框過程圖解,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下

這篇文章主要介紹了wxpython自定義下拉列表框過程圖解,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下

自定義wxpython下拉列表框,支持修改邊框顏色,按鈕圖標(biāo)的動態(tài)變換

原理同前兩片文章一樣,使用了兩個wx.staticText做邊框,一個文本框來顯示下拉列表的數(shù)據(jù),和一個圖片按鈕,實現(xiàn)下拉的標(biāo)志,和一個自帶的列表框,

影藏該列表框,不要原來的樣式,這里只需要使用它的展示列表的數(shù)據(jù)功能

自定義列表框的代碼:

class MyComBox:
  """自定義下拉列表框"""
  def __init__(self,parent,pos,size=(200,35),choices=[],readOnly=False,borderColor='#EAEAEA',borderSize=1):
    self.defaultfontSize = 10
    self.defaultBorderColor = '#EAEAEA'
    self.defaultFontColor = 'black'

    self.textCtrl,self.combox,self.background,self.arrow_button = self.__CreateComBox(parent,pos,size,
                                             choices,readOnly,borderColor,borderSize)
  def __CreateComBox(self,parent,pos,size,list,readOnly,borderColor,borderSize):
    #創(chuàng)建邊框
    border = wx.StaticText(parent,-1,"",pos=pos,size=size)
    border.SetBackgroundColour(borderColor)
    bg = wx.StaticText(border,-1,"",size=((size[0]-borderSize*2),(size[1]-borderSize*2)),pos=(borderSize,borderSize))
    style = wx.TE_READONLY | wx.NO_BORDER

    #創(chuàng)建數(shù)據(jù)展示框
    self.textCtrl = wx.TextCtrl(bg,-1,size=((size[0]-30),(self.defaultfontSize*2)),
                  pos=(5,(size[1]-2*self.defaultfontSize-borderSize*2)/2),style= style)
    self.textCtrl.SetBackgroundColour('white')
    #點擊文本框顯示數(shù)據(jù)
    if not readOnly:
      self.textCtrl.Bind(wx.EVT_LEFT_DOWN,self.__OnClick)

    #創(chuàng)建下拉點擊按鈕
    bmp = wx.Image("xia.jpg",wx.BITMAP_TYPE_ANY).ConvertToBitmap()
    arrow_button = wx.BitmapButton(bg,-1,bmp,size = (20,size[1]),pos=(size[0]-22,0),style =wx.NO_BORDER)

    #構(gòu)建列表框,展示列表的數(shù)據(jù)
    self.chooseBox = wx.ComboBox(parent,-1,value="",size=(size[0],-1),pos = (pos[0],pos[1]+10),choices=list,style=wx.TE_READONLY)
    self.chooseBox.Hide()
    self.chooseBox.Bind(wx.EVT_COMBOBOX_CLOSEUP,self.__GetValue)

    #設(shè)置顯示下列列表按鈕
    arrow_button.SetBackgroundColour('white')
    font = wx.Font(self.defaultfontSize,wx.DEFAULT,wx.NORMAL,wx.NORMAL,False,'微軟雅黑')
    self.textCtrl.SetFont(font)

    #設(shè)置只讀情況的樣式
    if readOnly:
      bg.SetBackgroundColour('rgb(240,240,240)')
      self.textCtrl.SetBackgroundColour('rgb(240,240,240)')
      arrow_button.SetBackgroundColour('rgb(240,240,240)')
    else:
     # bg.SetBackgroundColour(self.textCtrl.GetBackgroundColour())
      arrow_button.Bind(wx.EVT_BUTTON,self.__OnClick)

    return self.textCtrl,self.chooseBox,border,arrow_button

  def __GetValue(self,event):
    if self.chooseBox.GetValue()!='':
      self.textCtrl.SetValue(self.chooseBox.GetValue())
      self.chooseBox.Hide()
      bmp = wx.Image("xia.jpg",wx.BITMAP_TYPE_ANY).ConvertToBitmap()
      self.arrow_button.SetBitmap(bmp)
    if self.chooseBox.GetValue()!='請選擇':
      self.textCtrl.SetForegroundColour(self.defaultFontColor)


  def __OnClick(self,event):
    self.chooseBox.Show()
    self.chooseBox.Popup()
    bmp = wx.Image("shang.jpg", wx.BITMAP_TYPE_ANY).ConvertToBitmap()
    self.arrow_button.SetBitmap(bmp)

  def GetValue(self):
    return self.textCtrl.GetValue()

  def SetValue(self,value):
    if not value:
      value = u'請選擇'
    self.textCtrl.SetValue(value)
    self.combox.SetValue(value)


  def SetList(self,list):
    """設(shè)置下拉列表中的數(shù)據(jù)"""
    self.combox.SetItems(list)

  def SetBorderColor(self,color):
    self.background.SetBackgroundColour(color)


  def SetFont(self,font):
    self.textCtrl.SetFont(font)

  def SetForegroundColour(self,color):
    self.textCtrl.SetForegroundColour(color)

  def Bind(self, event, handler, source=None, id=wx.ID_ANY, id2=wx.ID_ANY):
    self.textCtrl.Bind(event,handler)

圖片:, ,這個需要下載下去,或者自己找漂亮的圖片

測試代碼:

# coding:utf-8
import wx

from wxpython import Mywxpython

app = wx.App()
frame = wx.Frame(None, title="Gui Test Editor", pos=(1000, 200), size=(500, 400))

panel = wx.Panel(frame)
panel.SetBackgroundColour('white')
# path_text = wx.TextCtrl(panel, size=(260, 36))
#
# my_text = Mywxpython.MyText(panel,pos=(10, 50),size=(260,36))
# my_text1 = Mywxpython.MyText(panel,pos=(10, 100),size=(260,36),readOnly=True)
# my_text.SetBorderColor('red')
list = ['1','2','3','4']
#wx.ComboBox(panel,-1,value="",size=(80,-1),pos = (100,110),choices=list,style=wx.TE_READONLY)

#my_button = Mywxpython.MyButton(panel,title="點我",pos=(10, 150))
combox = Mywxpython.MyComBox(panel,choices=['1','2','3','4'],pos=(10, 150))
#combox .SetValue("請選擇")
frame.Show()
app.MainLoop()

結(jié)果圖:

按鈕又有點丑,需要自己定義,搞兩個好看得圖標(biāo),

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • Pandas數(shù)據(jù)操作及數(shù)據(jù)分析常用技術(shù)介紹

    Pandas數(shù)據(jù)操作及數(shù)據(jù)分析常用技術(shù)介紹

    Pandas是Python中用于數(shù)據(jù)處理和數(shù)據(jù)分析的庫,具有強大的數(shù)據(jù)操作和分析功能,包括數(shù)據(jù)清洗、轉(zhuǎn)換、篩選、聚合等。常用技術(shù)有數(shù)據(jù)讀取與寫入、數(shù)據(jù)索引、數(shù)據(jù)切片、數(shù)據(jù)合并、數(shù)據(jù)透視表、數(shù)據(jù)可視化等,適用于各種數(shù)據(jù)分析和機器學(xué)習(xí)任務(wù)
    2023-04-04
  • Python實現(xiàn)for循環(huán)倒序遍歷列表

    Python實現(xiàn)for循環(huán)倒序遍歷列表

    這篇文章主要介紹了Python實現(xiàn)for循環(huán)倒序遍歷列表,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-05-05
  • python處理csv數(shù)據(jù)的方法

    python處理csv數(shù)據(jù)的方法

    這篇文章主要介紹了python處理csv數(shù)據(jù)的方法,實例分析了Python處理csv數(shù)據(jù)的技巧,需要的朋友可以參考下
    2015-03-03
  • 詳解Python 爬取13個旅游城市,告訴你五一大家最愛去哪玩?

    詳解Python 爬取13個旅游城市,告訴你五一大家最愛去哪玩?

    這篇文章主要介紹了Python 爬取13個旅游城市,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-05-05
  • 用Python做個個性的動畫掛件讓桌面不單調(diào)

    用Python做個個性的動畫掛件讓桌面不單調(diào)

    這篇文章主要介紹了如何用Python做個個性的動畫掛件,本文給大家介紹的非常詳細,對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2021-08-08
  • python實現(xiàn)2048小游戲

    python實現(xiàn)2048小游戲

    本文給大家分享的是個人修改自某網(wǎng)友的Python實現(xiàn)2048小游戲的代碼,推薦給大家,有需要的小伙伴可以參考下。
    2015-03-03
  • Django框架HttpResponse和HttpRequest對象學(xué)習(xí)

    Django框架HttpResponse和HttpRequest對象學(xué)習(xí)

    這篇文章主要介紹了Django框架HttpResponse和HttpRequest對象學(xué)習(xí),有需要的朋友可以借鑒參考下,希望可以有所幫助,祝大家早日升職加薪
    2021-09-09
  • 基于Python實現(xiàn)一個簡單的注冊機并生成卡密

    基于Python實現(xiàn)一個簡單的注冊機并生成卡密

    這篇文章主要為大家詳細介紹了如何使用Python編寫一個簡單而強大的注冊機,生成卡密來實現(xiàn)用戶注冊,從而輕松登錄應(yīng)用程序,有需要的小伙伴快可以參考下
    2023-12-12
  • 利用Python實現(xiàn)普通視頻變成動漫視頻

    利用Python實現(xiàn)普通視頻變成動漫視頻

    這篇文章主要為大家詳細介紹了如何利用Python語言實現(xiàn)普通視頻變成動漫視頻效果,文中的示例代碼講解詳細,感興趣的小伙伴可以了解一下
    2022-08-08
  • TensorFlow自定義模型保存加載和分布式訓(xùn)練

    TensorFlow自定義模型保存加載和分布式訓(xùn)練

    本篇文章將涵蓋 TensorFlow 的高級應(yīng)用,包括如何自定義模型的保存和加載過程,以及如何進行分布式訓(xùn)練,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2023-07-07

最新評論