practice_code/python/test/test2.py

31 lines
867 B
Python
Raw Normal View History

2024-04-20 01:36:15 +08:00
import wx
2024-04-20 17:36:36 +08:00
import wx.richtext as rt
2024-04-20 17:36:36 +08:00
class MyFrame(wx.Frame):
def __init__(self, parent, id, title):
wx.Frame.__init__(self, parent, id, title, size=(400, 300))
panel = wx.Panel(self)
vbox = wx.BoxSizer(wx.VERTICAL)
2024-04-20 01:36:15 +08:00
2024-04-20 17:36:36 +08:00
# 创建 RichTextCtrl
self.rtc = rt.RichTextCtrl(panel, style=wx.VSCROLL | wx.HSCROLL | wx.NO_BORDER | wx.WANTS_CHARS)
self.rtc.BeginFontSize(12)
self.rtc.WriteText("Here is some text, and here is an image: ")
self.rtc.EndFontSize()
2024-04-20 01:36:15 +08:00
2024-04-20 17:36:36 +08:00
# 插入图片
image = wx.Bitmap('path_to_your_image.png', wx.BITMAP_TYPE_PNG)
self.rtc.WriteImage(image)
2024-04-20 01:36:15 +08:00
2024-04-20 17:36:36 +08:00
vbox.Add(self.rtc, 1, flag=wx.EXPAND)
panel.SetSizer(vbox)
2024-04-20 01:36:15 +08:00
self.Show()
2024-04-20 17:36:36 +08:00
if __name__ == '__main__':
app = wx.App()
MyFrame(None, -1, 'Insert Image in RichTextCtrl')
2024-04-20 01:36:15 +08:00
app.MainLoop()