मैं wxPython में एक कस्टम बटन बनाना चाहता हूँ। मुझे कहां से शुरू करना चाहिए, मुझे यह कैसे करना चाहिए?Wx में कस्टम बटन कैसे बनाएं?
5
A
उत्तर
8
यहाँ एक कंकाल है जो आप पूरी तरह से कस्टम बटन आकर्षित करने के लिए उपयोग कर सकते हैं
class MyButton(wx.PyControl):
def __init__(self, parent, id, bmp, text, **kwargs):
wx.PyControl.__init__(self,parent, id, **kwargs)
self.Bind(wx.EVT_LEFT_DOWN, self._onMouseDown)
self.Bind(wx.EVT_LEFT_UP, self._onMouseUp)
self.Bind(wx.EVT_LEAVE_WINDOW, self._onMouseLeave)
self.Bind(wx.EVT_ENTER_WINDOW, self._onMouseEnter)
self.Bind(wx.EVT_ERASE_BACKGROUND,self._onEraseBackground)
self.Bind(wx.EVT_PAINT,self._onPaint)
self._mouseIn = self._mouseDown = False
def _onMouseEnter(self, event):
self._mouseIn = True
def _onMouseLeave(self, event):
self._mouseIn = False
def _onMouseDown(self, event):
self._mouseDown = True
def _onMouseUp(self, event):
self._mouseDown = False
self.sendButtonEvent()
def sendButtonEvent(self):
event = wx.CommandEvent(wx.wxEVT_COMMAND_BUTTON_CLICKED, self.GetId())
event.SetInt(0)
event.SetEventObject(self)
self.GetEventHandler().ProcessEvent(event)
def _onEraseBackground(self,event):
# reduce flicker
pass
def _onPaint(self, event):
dc = wx.BufferedPaintDC(self)
dc.SetFont(self.GetFont())
dc.SetBackground(wx.Brush(self.GetBackgroundColour()))
dc.Clear()
# draw whatever you want to draw
# draw glossy bitmaps e.g. dc.DrawBitmap
if self._mouseIn:
pass# on mouserover may be draw different bitmap
if self._mouseDown:
pass # draw different image text
3
उदाहरण के लिए इस तरह, डिफ़ॉल्ट बटन वर्ग का विस्तार कर सकते हैं:
class RedButton(wx.Button):
def __init__(self, *a, **k):
wx.Button.__init__(self, *a, **k)
self.SetBackgroundColour('RED')
# more customization here
हर बार जब आप अपने लेआउट में एक RedButton
शब्दों में कहें, यह लाल दिखाई देनी चाहिए (हालांकि यह परीक्षण नहीं किया)।
2
Generic Button या Bitmap Button का उपयोग करने का प्रयास करें।
5
जब मैं कैसे कस्टम विगेट्स बनाने के लिए सीखना चाहता था (बटन शामिल है) मैं wxPyWiki और कोड़ी Precord के platebutton पर Andrea Gavana's page (पूर्ण काम कर वहाँ उदाहरण) संदर्भित (स्रोत, SVN में here wx.lib.platebtn में है भी) । उन दोनों को देखो और आप जो भी कस्टम विजेट चाहते हैं उसे बनाने में सक्षम होना चाहिए। , अपनी कल्पना करने के लिए अपने ऊपर यह कैसा दिखता है या बर्ताव
आप इस के लिए बहुत बहुत धन्यवाद! मैं इसे बड़े पैमाने पर इस्तेमाल करूँगा! – Mizmor