2012-06-26 78 views
0

在这里,我试图模拟记事本,作为给定的任务,到目前为止,我编码动态更新SetTransparent和字体大小

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

要设置对话框的透明度,您需要调用其SetTransparency方法并将其传递给介于0和255之间的一个值。我在这个here上编写了一个教程。我还在wxPython中写了一个tutorial字体,它应该告诉你如何改变字体。基本上,您只需调用小部件的SetFont方法,然后调用小部件父级的Layout()方法以使更改显示出来。

+0

大拇指迈克,这有帮助...你能帮我一个东西..我想从一个wx.TextCtrl价值传递到另一个wx.TextCtrl框,现在如何刷新第二个框。就像当一个按钮被点击时。我正在使用AppendText来传递。任何方向我的这一点将不胜感激,并保存我的一天。而我传递的第二个盒子具有只读属性。 – Whiskey

+0

我很抱歉,我只是想通了。清除()属性清除东西.. – Whiskey

+1

你也可以使用myTextBox.SetValue(“”) –