【问题标题】:tkinter Text widget does not print input datatkinter Text 小部件不打印输入数据
【发布时间】:2019-02-22 04:13:23
【问题描述】:

我正在尝试通过 tkinter 文本小部件获取输入。我看到了关于 tkinter 文本小部件输入的帖子。但那些对我不起作用。我在 上看到了帖子并尝试过,但我不明白它有什么问题。这是我的代码。

`corpusinput = Text(rooter, width=50, height=10)
 corpustext = corpusinput.get("1.0", "end-1c")
 corpusinput.grid(row=2, column=1, sticky='nsew')
 print(corpustext)`

这会打印一个没有任何字符的空格/行。

【问题讨论】:

    标签: python-3.x tkinter


    【解决方案1】:

    您在创建小部件后就在它上调用.get() 方法。此时小部件为空白,因此.get() 将返回''

    您需要设置一种在程序运行时调用.get() 的方式,例如。一个按钮

    corpusinput = Text(rooter, width=50, height=10)
    corpusinput.grid()
    
    get_input = Button(rooter, text='Print', command= lambda x=corpusinput.get() : print(x))
    get_input.grid()
    

    【讨论】:

      猜你喜欢
      • 2022-11-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-20
      • 2021-07-06
      • 1970-01-01
      • 1970-01-01
      • 2018-11-17
      相关资源
      最近更新 更多