wxPython – wx.StaticText 中的 CaptureMouse()
Python提供wxpython 包允许我们创建功能强大的图形用户界面。它是Python的跨平台GUI工具包,Phoenix版Phoenix是改进的下一代wxPython,主要关注速度、可维护性和可扩展性。
在本文中,我们将了解与 wxPython 的wx.StaticText类关联的CaptureMouse()方法。 CaptureMouse()方法将鼠标光标移到静态文本上时进入加载模式。 CaptureMouse()函数不接受任何参数。
Syntax: wx.StaticText.CaptureMouse(self)
Parameters: CaptureMouse() method takes no arguments.
例子:
Python3
# importing wx library
import wx
# create an Example class
class Example(wx.Frame):
# constructor
def __init__(self, *args, **kwargs):
super(Example, self).__init__(*args, **kwargs)
# method calling
self.InitUI()
# method for user interface creation
def InitUI(self):
self.locale = wx.Locale(wx.LANGUAGE_ENGLISH)
# create parent panel
self.pnl = wx.Panel(self)
# create static text at point (20,20)
self.st = wx.StaticText(self.pnl, id = 1,
label = "StaticText",
pos = (20,20))
# capture mouse on static text
self.st.CaptureMouse()
self.SetSize((350, 250))
self.SetTitle('wx.Button')
self.Centre()
# main function
def main():
# create an App object
app = wx.App()
# create an Example object
ex = Example(None)
ex.Show()
# running a app
app.MainLoop()
# Driver code
if __name__ == '__main__':
# main function call
main()
输出: