简体   繁体   中英

How can wxThumbnailCtrl in wxpython be used?

I think this is a new widget and theres no examples online about this. im not sure how i should start using it or how it can be used.

Here is simple example to get you started. self.button selects directory with images; on doubleclick on any of thumbnails a messagebox is shown with info on selected thumb.

import wx
from wx.lib.agw import thumbnailctrl as tn

class MyFrame(wx.Frame):
    def __init__(self, *args, **kwds):
        wx.Frame.__init__(self, *args, style=wx.DEFAULT_FRAME_STYLE)
        self.button = wx.Button(self, -1, "Select dir")
        self.Bind(wx.EVT_BUTTON, self.ButtonPress, self.button)
        self.tn = tn.ThumbnailCtrl(self)    
        self.tn.Bind(tn.EVT_THUMBNAILS_DCLICK, self.TnClick)

        box = wx.BoxSizer(wx.VERTICAL)
        box.Add(self.tn, 1, wx.EXPAND, 0)
        box.Add(self.button, 0, wx.ADJUST_MINSIZE, 0)
        self.SetSizer(box)
        box.Fit(self)
        self.Layout()

    def ButtonPress(self, evt):
        dlg = wx.DirDialog(self, 'Get dir')
        if dlg.ShowModal() == wx.ID_OK:
        path = dlg.GetPath()
        dlg.Destroy()
        self.tn.ShowDir(path)

    def TnClick(self, evt):
        sel = self.tn.GetSelection()
        wx.MessageBox(self.tn.GetThumbInfo(sel))

if __name__ == "__main__":
    app = wx.PySimpleApp(0)
    frame = MyFrame(None, -1, "")
    frame.Show()
    app.MainLoop()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM