- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我是 Python 新手,所以我也是 wxPython 新手。我只是想知道这些 wx.TextCtrl 函数之间是否有任何区别。这个迷你代码显示了三倍相同的输出。如果没有差异,这些功能是否有历史原因?
import wx
class testUI(wx.Panel):
textCtrl = ''
def __init__(self, parent, name):
super(testUI, self).__init__(parent, name=name)
self.buildUI()
self.Show(True)
self.textCtrl.write('bli\n')
self.textCtrl.WriteText('bla\n')
self.textCtrl.AppendText('blub\n')
def buildUI(self):
self.textCtrl = wx.TextCtrl(self, style=wx.TE_MULTILINE|wx.TE_READONLY)
box = wx.BoxSizer(wx.VERTICAL)
box.Add(self.textCtrl, proportion=1, flag=wx.EXPAND)
def main():
app = wx.App(False)
root = wx.Frame(parent=None, title='testUI')
testUI(parent=root, name='testUI')
root.Show(True)
app.MainLoop()
# Standard boilerplate to call the main() function.
if __name__ == '__main__':
main()
谢谢:)
最佳答案
猜测人们可能出于与我相同的原因点击此线程,即 wxPython (4.0.1) 的"new"版本将 write() 列为 wx.TextCtrl 类上的方法 - 但它没有定义。我需要一个写入函数才能使用logging.StreamHandler类;因为这些方法都应该做同样的事情,所以我通过赋值重新创建了缺少的 write 方法 - 这有效:
import wx
import logging
lgr = logging.getLogger(__name__)
lgr.setLevel(logging.DEBUG)
fmt = logging.Formatter('%(asctime)s: %(name)s [%(levelname)s] %(message)s')
debug = lgr.debug
class LogTab(wx.Panel):
def __init__(self, *args, **kwds):
kwds["style"] = wx.TAB_TRAVERSAL
wx.Panel.__init__(self, *args, **kwds)
self.text_log = wx.TextCtrl(self, wx.ID_ANY, "",
style=wx.TE_MULTILINE | wx.TE_READONLY)
self.text_log.write = self.text_log.WriteText
self.__set_properties()
self.__do_layout()
self.log_handler = logging.StreamHandler(self.text_log)
self.log_handler.setFormatter(fmt)
lgr.addHandler(self.log_handler)
关于python - wx.TextCtrl .write/.WriteText/.AppendText 之间的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26614187/
已解决:感谢下面 Aya 的回答,我现在知道问题是由第 18 行的 self.panel = wx.Panel(self, -1) 引起的。我创建了一个面板,但没有在其上附加任何内容。原始问题描述仍如
我想要一个 wx.TextCtrl获取面板的整个剩余宽度。它放置了一个 wx.StaticText和一个 wx.Button在水平 wx.BoxSizer在垂直 wx.BoxSizer在 wx.lib
我正在寻找一种将 textctrl 字段中输入的文本转换为大写的方法。我尝试使用验证器并使用“ord”将键事件对象的值转换为大写字母字符值,但是我找不到任何“set”方法。我也许能够直接访问事件类变量
我正在寻找一种将 textctrl 字段中输入的文本转换为大写的方法。我尝试使用验证器并使用“ord”将键事件对象的值转换为大写字母字符值,但是我找不到任何“set”方法。我也许能够直接访问事件类变量
我正在使用 wxPython-Phoenix 在 MS Windows 8.1 上编写一个计算器应用程序,其中我希望用户在其中一个参数字段中输入值时立即执行计算。为了实现这一点,我使用由任何参数字段生
我写了这段代码: # -*- coding: utf-8 -*- import wx import wx.animate import wx.lib.agw.hyperlink as hl ID_BU
平台窗口 使用 Windows API 创建了一个控件:CreateWindowExW 并将其父级设置为面板 hwnd 但控件似乎无法正确处理方向键、回车键和制表键。 wxwidgets 上是否有任何
我正在开发一个 GUI 程序,我使用 AppendText 来更新多行文本框(由 wx.TextCtrl 组成)中的状态。我注意到每次在此框中写入一个新行,而不是顺利地将此行添加到末尾,框中的整个文本
我一定是使用了错误的术语进行谷歌搜索,因为我找不到我要找的东西。任何帮助表示赞赏。 如何写入 textctrl 中的特定行? 当前我的程序处理文件,处理后文件会在文本 ctrl 中列出。我想要达到的目
所以,我正在尝试使用 wxPython 编写一个程序,该程序将有一个带有选项卡的笔记本,每个选项卡都让用户在文本框中输入一些数据。这是一个与物理相关的项目,所以我希望每个文本框在显示应输入的单位后都有
有人知道如何使用 wxPython 在 TextCtrl 对象中创建自定义上下文菜单吗? 目前,我可以创建一个自定义菜单,但这个菜单出现在鼠标光标位置 ,当原来的出现在文本光标位置 时当按下[菜单]键
我想做一个没有边框的 wx.TextCtrl wxpython :P我该怎么做? 最佳答案 wx.BORDER_NONE 怎么样: t1 = wx.TextCtrl(self, -1, "my tex
我在将 wx.TextCtrl 中的文本居中时遇到困难(如下图所示)。 -- 出于某种原因,它总是打印左对齐,而不是居中。 有人可以指出正确的“样式”或者告诉我哪里做错了吗? import wx cl
我有多行,在wxpython中只读TextCtrl我知道如何使用 设置值 myTextCtrl.SetValue('hello') 但这会改变我之前在我的 TextCtrl 中的任何内容...如何添加
如何从 TextCtrl 框中获取字符串?下面是练习代码: import wx class citPanel(wx.Panel): def __init__(self, parent, id)
我在我的 python 应用程序中使用了一个模块,该模块使用日志记录模块写入大量消息。最初我在控制台应用程序中使用它,使用控制台处理程序很容易让日志输出显示在控制台上。现在我已经使用 wxPython
我有一个文本(有多行),需要将其放入 wxPython TextCtrl 中。 问题是其中一些行包含无法打印的字符。 我的解决方案是使用 AppendText,并 try catch 有问题的行。 当
我正在 wxpython 中为 wx.TextCtrl 创建一个子类。 我希望此类将额外数据添加到 wx.TextCtrl 小部件,类似于将额外数据添加到 ComboBox 或 ListBox 的方式
我正在编写一个与 Skype 集成的聊天程序。我已经完成了大部分跑腿工作,但我在 wxPython 中的 Notebook 控件方面遇到了问题。我想当用户发送消息时在笔记本上创建一个新选项卡,我正在工
我的代码如下 log = wx.TextCtrl(面板, wx.ID_ANY, size=(300,100), 样式 = wx.TE_MULTILINE|wx.TE_READONLY|wx.HSCRO
我是一名优秀的程序员,十分优秀!