【发布时间】:2016-12-20 13:36:46
【问题描述】:
我刚开始使用 tkinter 和 python3。我正在使用 pygubu 尝试制作一个非常简单的方法,它从 Entry 小部件中获取输入,并在按下按钮时将其显示在 Messagebox 中。以下是我正在使用的代码:
# command_properties.py
import tkinter as tk
from tkinter import messagebox
import pygubu
# define the function callbacks
def on_button1_click():
tk_messageBox -message answer -type ok -icon info
class MyApplication(pygubu.TkApplication):
def _create_ui(self):
#1: Create a builder
self.builder = builder = pygubu.Builder()
#2: Load an ui file
builder.add_from_file('test.ui')
#3: Create the widget using self.master as parent
self.mainwindow = builder.get_object('Frame_1', self.master)
# Configure callbacks
callbacks = {
'on_button1_clicked': on_button1_click
}
builder.connect_callbacks(callbacks)
if __name__ == '__main__':
root = tk.Tk()
app = MyApplication(root)
app.run()
这里是ui文件代码:http://pastebin.com/puRbD87m 另外,请告诉我我具体哪里错了。
【问题讨论】:
-
您似乎没有尝试过完成这项工作。您需要尝试创建
on_button1_click函数,然后在遇到更具体的问题时提出问题,然后“告诉我我错在哪里”。此外,本网站强烈不鼓励链接到其他网站上的代码。这可能会发生变化,或者该网站可能会关闭,从而使这个问题在未来对其他人毫无用处。
标签: python-3.x tkinter ttk