ruby - 不确定如何从 tk 条目或 ruby 中的文本小部件获取文本
问题描述
我想要完成的是从 TkEntry 小部件中检索条目字符串并使用该字符串将 TkLabel 文本变量更改为:
require 'tk'
class Gui
def procc
label['textvariable'] = $user_input
end
root = TkRoot.new {title "Gui Test"}
root['geometry'] = '500x500'
label = TkLabel.new(root) do
textvariable
pack("padx" => "15", "pady" => "15")
end
label['textvariable'] = "Label"
button = TkButton.new(root) do
text "Button"
pack("padx" => "15", "pady" => "15")
command (proc {procc})
end
check_button = TkCheckButton.new(root) do
text "Check Mate"
pack("padx" => "15", "pady" => "15")
end
$user_input = TkVariable.new
e = Tk::Tile::Entry.new(root) {textvariable = $user_input}
e.pack()
end
Gui.new
Tk.mainloop
解决方案
对我来说,以下代码(从您的示例中调整)永久使用 TkEntry 中的值更新 TkLabel:
require 'tk'
class Gui
root = TkRoot.new {title "Gui Test"}
root['geometry'] = '500x500'
$user_input = TkVariable.new
label = TkLabel.new(root) do
textvariable $user_input
pack("padx" => "15", "pady" => "15")
end
$user_input.value = "Label"
button = TkButton.new(root) do
text "Button"
pack("padx" => "15", "pady" => "15")
command (proc {})
end
check_button = TkCheckButton.new(root) do
text "Check Mate"
pack("padx" => "15", "pady" => "15")
end
e = Tk::Tile::Entry.new(root) {textvariable $user_input}
e.pack()
end
Gui.new
Tk.mainloop
推荐阅读
- python - 使用 BeautifulSoup 从 HTML 文件中丢失元素
- python - 具有多维索引列表的 Numpy 掩码
- php - 使用 REGEX 或 LIKE 从多个列中进行选择
- javascript - 您如何/可以在数组中加入/组合单个字符串?
- c - 为什么管道操作在我的 shell 中不起作用?
- python - 我无法在 python 或solidity 中导入我需要的任何东西
- apache-spark - EMR Spark 内存管理 - 不同的执行器内存
- shell - 如何在不绑定到启动脚本的情况下查看来自应用程序的标准输出消息
- flowchart - 如何创建具有多个水平和垂直车道的泳道?
- javafx - 固定单元格大小不适用于 css 文件