2.构建一个简单的文本编辑器
2015-12-14 10:24
459 查看
Windows or Frames?
When people talk about GUIs, they usually speak of windows, menus and icons. Naturally then, you would expect thatwx.Window should represent a window on the screen. Unfortunately, this is not the case. Awx.Window is the baseclass from which all visual elements are derived (buttons, menus, etc) and what we normally think of as a program window is awx.Frame. This is an unfortunate inconsistency that has led to much confusion for new users.
窗口和框架?
当人们谈论起GUIs,他们通常说的是窗口,菜单和图标。自然地,你也期待wx.Window应该是代表屏幕上的一个窗口。
不幸的是,情况不是这样的。一个wx.Window是一个基类,它从视觉派生而来(buttons,menus,等),并且我们通常认为作为一个程序的窗口就是wx.Frame。
这是一个不幸的前后矛盾,这已经导致了许多新手感到困惑。
构建一个简单的文本编辑器
在本教程中,我们将构建一个简单的文本编辑器。在这个过程中,我们将研究几个小部件,并了解特性,比如事件和回调。
第一步是要做一个简单的框架内与一个可编辑的文本框。一个文本框是TextCtrl小部件。默认情况下,一个文本框是一个单行的领域,但是wx.TE_MULTILINE参数允许您输入多个文本的行。
[python] view
plaincopy
import wx
class MyFrame(wx.Frame):
def __init__(self,parent,title):
wx.Frame.__init__(self,parent,title=title,size=(400,300))
self.control = wx.TextCtrl(self,style=wx.TE_MULTILINE)
self.Show(True)
app = wx.App(False)
frame = MyFrame(None,"Small Editor")
app.MainLoop()
这个例子里,我们从wx.Frame派生并重写它的__init__方法。声明一个可以编辑TextCtrl控件。
请注意,因为在MyFrame的内部运行它的__init__方法self.Show(),我们不再需要显式地调用frame.Show()。
相关文章推荐
- 1.第一个程序: "Hello, World"
- 【使用】Xcode插件使用简析
- 排序与时间复杂度
- 使用 android studio 查看 android 源码
- 代码农民提高生产力
- 编程的智慧
- 获取设备实际宽度
- mui开发
- JS面向对象
- JavaFX 指定路径的球
- CSS布局note
- 深入浅析Java中的final关键字
- 3.LINUX后台进程与前台进程的区别
- 白手起家学习数据科学 ——k-Nearest Neighbors之“背后的思想”(九)
- Android4.0 input touch解析
- 分治法之快速排序算法
- 每天一个linux命令--awk
- 遇到崩了的情况
- 全球域名商解析新增保有量20强:万网、易名落榜
- JavaFX 之弹跳球