动态更新SetTransparent和字体大小

时间:2012-06-26 20:29:41

标签: python user-interface wxpython

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

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

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

1 个答案:

答案 0 :(得分:1)

要设置对话框的透明度,您需要调用其SetTransparency方法并将其传递给0到255之间的数量。我在此here上编写了一个教程。我还在wxPython中写了一个tutorial字体,它应该告诉你如何更改字体。基本上你只需要调用widget的SetFont方法,然后可能调用widget的父对象的Layout()方法来显示更改。