用wxPython写一个带有右侧滚动条的 打开bmp图片 点击图片位置返回坐标的demo
时间: 2023-05-28 19:01:53 浏览: 109
滚动条demo
import wx
class MyFrame(wx.Frame):
def __init__(self, parent, title):
wx.Frame.__init__(self, parent, title=title, size=(400, 400))
panel = wx.Panel(self)
self.scroll = wx.ScrolledWindow(panel, size=(-1, -1), style=wx.TAB_TRAVERSAL | wx.SUNKEN_BORDER)
self.scroll.SetScrollbars(1, 1, 600, 400)
self.SetMinSize((400, 400))
self.img = wx.Image('image.bmp', wx.BITMAP_TYPE_BMP)
self.bmp = wx.StaticBitmap(self.scroll, -1, wx.Bitmap(self.img))
self.bmp.Bind(wx.EVT_LEFT_DOWN, self.OnLeftDown)
def OnLeftDown(self, event):
x, y = event.GetPositionTuple()
self.SetTitle('Clicked on (%d, %d)' % (x, y))
if __name__ == '__main__':
app = wx.App()
frame = MyFrame(None, 'Image Viewer')
frame.Show(True)
app.MainLoop()
阅读全文