gpt4 book ai didi

python - 如何显示 wx 模块中的文本?

转载 作者:太空宇宙 更新时间:2023-11-03 18:48:39 25 4
gpt4 key购买 nike

昨天发现我的路由器可以通过telnet控制,今天我正在寻找一些qt4,pygtk或wx来将所有路由器telnet命令存储在gui中。不到 15 分钟前,我发现了这个网站 - zetcode(dot)com/wxpython/advanced/,它提供了我需要的正确信息。不幸的是,我不明白如何在 wx 模块中包含文本,因为我是第一次使用它。您能告诉我如何将文本分配给左侧窗口吗?因为一旦我启动该模块,它就会显示一个灰色屏幕,菜单中带有按钮。最左边的灰色区域必须包含大约 10 个 telnet 命令,其中“帮助”包含保存在 html 文件中的所有命令。

import wx
import wx.html as html

class HelpWindow(wx.Frame):
def __init__(self, parent, id, title):
wx.Frame.__init__(self, parent, id, title, size=(570, 400))
toolbar = self.CreateToolBar()
toolbar.AddLabelTool(1, 'Exit', wx.Bitmap('icons/exit.png'))
toolbar.AddLabelTool(2, 'Help', wx.Bitmap('icons/help.png'))
toolbar.Realize()

self.splitter = wx.SplitterWindow(self, -1)
self.panelLeft = wx.Panel(self.splitter, -1, style=wx.BORDER_SUNKEN)

self.panelRight = wx.Panel(self.splitter, -1)
vbox2 = wx.BoxSizer(wx.VERTICAL)
header = wx.Panel(self.panelRight, -1, size=(-1, 20))
header.SetBackgroundColour('#6f6a59')
header.SetForegroundColour('WHITE')
hbox = wx.BoxSizer(wx.HORIZONTAL)

st = wx.StaticText(header, -1, 'Help', (5, 5))
font = st.GetFont()
font.SetPointSize(9)
st.SetFont(font)
hbox.Add(st, 1, wx.TOP | wx.BOTTOM | wx.LEFT, 5)

close = wx.BitmapButton(header, -1, wx.Bitmap('icons/fileclose.png', wx.BITMAP_TYPE_PNG),
style=wx.NO_BORDER)
close.SetBackgroundColour('#6f6a59')
hbox.Add(close, 0)
header.SetSizer(hbox)

vbox2.Add(header, 0, wx.EXPAND)

help = html.HtmlWindow(self.panelRight, -1, style=wx.NO_BORDER)
help.LoadPage('wx.html')
vbox2.Add(help, 1, wx.EXPAND)
self.panelRight.SetSizer(vbox2)
self.panelLeft.SetFocus()

self.splitter.SplitVertically(self.panelLeft, self.panelRight)
self.splitter.Unsplit()

self.Bind(wx.EVT_BUTTON, self.CloseHelp, id=close.GetId())
self.Bind(wx.EVT_TOOL, self.OnClose, id=1)
self.Bind(wx.EVT_TOOL, self.OnHelp, id=2)

self.Bind(wx.EVT_KEY_DOWN, self.OnKeyPressed)

self.CreateStatusBar()

self.Centre()
self.Show(True)

def OnClose(self, event):
self.Close()

def OnHelp(self, event):
self.splitter.SplitVertically(self.panelLeft, self.panelRight)
self.panelLeft.SetFocus()

def CloseHelp(self, event):
self.splitter.Unsplit()
self.panelLeft.SetFocus()

def OnKeyPressed(self, event):
keycode = event.GetKeyCode()
if keycode == wx.WXK_F1:
self.splitter.SplitVertically(self.panelLeft, self.panelRight)
self.panelLeft.SetFocus()


app = wx.App()
HelpWindow(None, -1, 'HelpWindow')
app.MainLoop()

最佳答案

找到了...

wx.StaticText(self.panelLeft, -1, 'thetextgoeshere', (15, 5))

关于python - 如何显示 wx 模块中的文本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18875740/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com