0

在这里我试图模拟记事本,作为给定的任务,到目前为止我编码

import wx

class MyFrame(wx.Frame):
    def __init__(self, parent, title):
        wx.Frame.__init__(self, parent, title=title, size=(500,500))
        self.control = wx.TextCtrl(self, style=wx.TE_MULTILINE | wx.HSCROLL)
        self.control.SetBackgroundColour('black'), self.control.SetForegroundColour('green')
        self.SetTransparent(225)

        #Create Status Bar
        self.CreateStatusBar()

        #Create Menus
        menu1 = wx.Menu()
        menu1.Append(wx.ID_NEW, "&New File...  Ctrl+N", "Create A New File")
        menu1.Append(wx.ID_OPEN, "&Open...       Ctrl+O", "Open An Existing File")
        menu1.Append(wx.ID_SAVE, "&Save...       Ctrl+S", "Save The File")
        menu1.Append(wx.ID_SAVEAS, "&Save As", "Save The File With Extension Type")
        menuquit = menu1.Append(wx.ID_EXIT, "&Quit...         Ctrl+Q", "Close")
        self.Bind(wx.EVT_MENU, self.OnQuit, menuquit)

        menu2=wx.Menu()
        menu2.Append(wx.ID_UNDO, "&Undo... \tCtrl+Z", "Undo Selection")
        menu2.Append(wx.ID_CUT, "&Cut... \tCtrl+X", "Cuts A Selected Part")
        menu2.Append(wx.ID_COPY, "&Copy... \tCtrl+C", "Copy Selection")
        menu2.Append(wx.ID_PASTE, "&Paste... \tCtrl+V", "Paste The Coped Selection")
        menu2.Append(wx.ID_DELETE, "&Delete... \tDel", "Deletes A Selection")
        menu2.Append(wx.ID_REPLACE, "&Replace", "Replaces")
        menu2.Append(wx.ID_SELECTALL, "&Select All... \tCtrl+A", "Selects All")

        menu3=wx.Menu()
        menu3.Append(wx.NewId(), "Word Wrap... F10", "Word Wrap Option")
        menu3.Append(wx.NewId(), "Fonts", "Select Fonts")

        menu4=wx.Menu()
        menu4.Append(wx.ID_HELP, "&Help Topics", "Help Topic")
        menupy = menu4.Append(wx.ID_ABOUT, "&About PyPad", "About PyPad")
        self.Bind(wx.EVT_MENU, self.OnPyPad, menupy)

        #creating MenuBar
        menubar = wx.MenuBar()
        menubar.Append(menu1, "&File")
        menubar.Append(menu2, "&Edit")
        menubar.Append(menu3, "&Format")
        menubar.Append(menu4, "&Help")

        #Set the Menu Bar
        self.SetMenuBar(menubar)

        #Show the Frame
        self.Show(True)

    def OnPyPad(self, e):
         dlg = wx.MessageDialog(self, "A Text Editor With wxPython.", "About Sample Editor",wx.OK)
         dlg.ShowModal()
         dlg.Destroy()
    def OnQuit(self, e):
         self.Close()        

app = wx.App(True)
frame = MyFrame(None, "Py Editor")
app.MainLoop()

现在,在这里我被要求创建对话框,当单击帮助时,我做了,现在我应该如何动态更新透明度?并且还使字体更大,也许是一些字体属性。:S

需要一些帮助,请注意,这只是一个必须完成的模拟器,添加的菜单仅用于显示目的,我可以添加尽可能多的菜单。

4

1 回答 1

2

要设置对话框的透明度,您需要调用它的 SetTransparency 方法并传递一个介于 0 和 255 之间的数值。我在此处写了一篇关于此的教程。我还写了一篇关于 wxPython 中字体的教程,它应该会告诉你如何更改字体。基本上,您只需调用小部件的 SetFont 方法,然后调用小部件父级的 Layout() 方法即可显示更改。

于 2012-06-27T20:48:04.443 回答