如何使用 Pygubu - Python
How to use Pygubu - Python
我第一次尝试使用 pygubu 来制作更好的 GUI。我已经使用 pip 安装了它并且安装正确。但是,当我尝试 运行 示例代码 Here (At the bottom of the web page) 时,我收到错误
AttributeError: module 'pygubu' has no attribute 'Builder'
不知道这段代码对不对。我一直在寻找使用此工具的方法,但我只能找到 link 和安装它的视频。我也试过 This video 但不知道如何 open/run/use。如果这是问题所在,我正在使用 python-idle。代码(如果你不想遵循 link)是:
# helloworld.py
import tkinter as tk
import pygubu
class HelloWorldApp:
def __init__(self):
#1: Create a builder
self.builder = builder = pygubu.Builder()
#2: Load an ui file
builder.add_from_file('helloworld.ui')
#3: Create the mainwindow
self.mainwindow = builder.get_object('mainwindow')
def run(self):
self.mainwindow.mainloop()
if __name__ == '__main__':
app = HelloWorldApp()
app.run()
如有任何帮助,我将不胜感激。此外,当我再次尝试安装它时 - 只是为了检查 - 我得到:
Pygubu 是一个应用程序。在 C: 驱动器的文件中找到它。代码:
# helloworld.py
import tkinter as tk
import pygubu
class HelloWorldApp:
def __init__(self):
#1: Create a builder
self.builder = builder = pygubu.Builder()
#2: Load an ui file
builder.add_from_file('helloworld.ui')
#3: Create the mainwindow
self.mainwindow = builder.get_object('mainwindow')
def run(self):
self.mainwindow.mainloop()
if __name__ == '__main__':
app = HelloWorldApp()
app.run()
是 运行 在您创建 UI(此应用程序使用的格式)并且指定的 UI 的名称是 helloworld.ui 之后。
Note that instead of helloworld.ui in the following line:
builder.add_from_file('helloworld.ui') You should insert the filename
(or path) of your just saved UI definition.
Note also that instead of 'mainwindow' in the following line:
self.mainwindow = builder.get_object('mainwindow') You should have the
name of your main widget (the parent of all widgets), otherwise you
will get an error similar to the following:
Exception: Widget not defined.
This link explains the usage better than one stated in question
我第一次尝试使用 pygubu 来制作更好的 GUI。我已经使用 pip 安装了它并且安装正确。但是,当我尝试 运行 示例代码 Here (At the bottom of the web page) 时,我收到错误
AttributeError: module 'pygubu' has no attribute 'Builder'
不知道这段代码对不对。我一直在寻找使用此工具的方法,但我只能找到 link 和安装它的视频。我也试过 This video 但不知道如何 open/run/use。如果这是问题所在,我正在使用 python-idle。代码(如果你不想遵循 link)是:
# helloworld.py
import tkinter as tk
import pygubu
class HelloWorldApp:
def __init__(self):
#1: Create a builder
self.builder = builder = pygubu.Builder()
#2: Load an ui file
builder.add_from_file('helloworld.ui')
#3: Create the mainwindow
self.mainwindow = builder.get_object('mainwindow')
def run(self):
self.mainwindow.mainloop()
if __name__ == '__main__':
app = HelloWorldApp()
app.run()
如有任何帮助,我将不胜感激。此外,当我再次尝试安装它时 - 只是为了检查 - 我得到:
Pygubu 是一个应用程序。在 C: 驱动器的文件中找到它。代码:
# helloworld.py
import tkinter as tk
import pygubu
class HelloWorldApp:
def __init__(self):
#1: Create a builder
self.builder = builder = pygubu.Builder()
#2: Load an ui file
builder.add_from_file('helloworld.ui')
#3: Create the mainwindow
self.mainwindow = builder.get_object('mainwindow')
def run(self):
self.mainwindow.mainloop()
if __name__ == '__main__':
app = HelloWorldApp()
app.run()
是 运行 在您创建 UI(此应用程序使用的格式)并且指定的 UI 的名称是 helloworld.ui 之后。
Note that instead of helloworld.ui in the following line:
builder.add_from_file('helloworld.ui') You should insert the filename (or path) of your just saved UI definition.
Note also that instead of 'mainwindow' in the following line:
self.mainwindow = builder.get_object('mainwindow') You should have the name of your main widget (the parent of all widgets), otherwise you will get an error similar to the following:
Exception: Widget not defined.
This link explains the usage better than one stated in question