- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我是一名 Python 菜鸟,试图将我通过教程学到的一些东西结合起来;专门用 guizero 制作一个 GUI。
我创建了一个名为 player_name 的 TextBox 对象和一个名为 create_story 的 PushButton 对象。我的目标是在文本框为空时禁用该按钮,并在文本框中输入内容时启用该按钮。
guizero 文档列出了“enable()”和“disable()”作为附加到 PushButton 的方法,但没有详细说明:https://lawsie.github.io/guizero/pushbutton/#methods
到目前为止的完整代码:
import random
from guizero import App, Text, TextBox, PushButton, ButtonGroup, Combo, Box
def print_story():
print("Button Pressed")
app = App(title="Visual Adventure", width=550, height=400,)
hello_message = Text(app, text="Hello, Traveler", size=20, color="red")
story_message = Text(app, text="Would you like to hear a tale?", size=14, color="black")
# organize into box with grid
selections = Box(app, layout="grid")
# text for questions
name_ques = Text(selections, text="What is your name?", size=10, color="black", grid=[0,0], align="left")
gender_ques = Text(selections, text="Boy or a girl?", size=10, color="black", grid=[0,2], align="left")
day_ques = Text(selections, text="What day is it?", size=10, color="black", grid=[0,4], align="left")
# text for grid padding
pad1 = Text(selections, text=" ", size=10, grid=[0,1], align="left")
pad2 = Text(selections, text=" ", size=10, grid=[0,3], align="left")
# interactive objects
player_name = TextBox(selections, width=15, grid=[1,0], align="top")
player_gender = ButtonGroup(selections, options=[ ["Boy", "He"], ["Girl", "She"] ], selected="He", horizontal=True, grid=[1,2], align="top")
day_set = Combo(selections, options=["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"], selected="Monday", grid=[1,4], align="top")
create_story = PushButton(app, command=print_story, text="Tell me!")
if not player_name.get():
create_story.disable()
elif player_name.get():
create_story.enable()
app.display()
错误:
Traceback (most recent call last):
File "/home/pi/Desktop/python/VisualAdventure.py", line 32, in <module>
create_story.disable()
File "/usr/local/lib/python3.4/dist-packages/guizero/PushButton.py", line 59, in disable
self.config(state=DISABLED)
NameError: name 'DISABLED' is not defined
最佳答案
恭喜您,您发现了一个错误。正如包装上所述:
This is a pre-release version, so there may be bugs and features may change.
因为 guizero 仍处于 alpha 版本,所以仍然有 bug 有待发现。犯这个错误的具体 promise 是: https://github.com/lawsie/guizero/commit/236064b8781c298a87954775daed65cb384d04f4 (实际上,那里没有犯任何错误,实际上是在lawsie merged拉取请求时)。正如你所看到的here ,那个人忘记导入 tkinter.DISABLE
和 tkinter.ENABLE
。
您可以在此处报告问题:https://github.com/lawsie/guizero/issues希望他们尽快改变它,因为这是一个非常简单的修复。
关于python - guizero/tkinter PushButton NameError 来自 guizero PushButton.py,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44223606/
我是一名 Python 菜鸟,试图将我通过教程学到的一些东西结合起来;专门用 guizero 制作一个 GUI。 我创建了一个名为 player_name 的 TextBox 对象和一个名为 crea
使用 PyQt,我想创建一个满足这组规则的用户界面: 棋盘由大小为 (s,s) 的二维网格组成,其中 s 为奇数 这个网格的每个小部件都是一个 QtPushButton 当我们初始化 UI 时,除了中
我正在使用一个按钮来记录传入的麦克风声音信号。通常,信号在按下记录按钮后到达有点晚,我记录的输出包含零直到 10 毫秒(之后我收到实际输出)。我正在使用以下 QTimer 函数来设置延迟,但输出是相同
我可以使用 FileSaveDialog1.Dialog.QueryInterface 创建一个按钮,如下所示。如何设置和处理 OnPushButton 单击事件以便我可以响应按钮单击? proced
我是这个论坛以及 Python 和 PyQt 的新手。在学习了一些基础知识之后,在尝试使用 Qt 学习动画时,我希望编写一个简单的应用程序,其中通过单击另一个按钮将按钮动画地从屏幕左侧带到某个位置。在
我开始学习 Qt 和编码。我有一个基本的项目,用于练习目的。 这是我的小 UI 的图片: 请耐心等待,因为我才刚开始使用 cpp。 我希望 QPushButton 在我单击后将此字符串 -> “文本”
我正在尝试创建带有自定义颜色和图像/文本的按钮。添加颜色和图像/文本非常容易,但现在我在垂直对齐方面遇到了问题。 “text-alignment: center”帮助我实现了水平对齐,但在垂直方面却没
我正在构建 2 列按钮,在升级到 GWT 2.4.0 之后,我的点击事件出现了问题。 在电脑上单击按钮后,您必须移动鼠标位置才能触发事件。在 iPad 上,必须再次按下该按钮。 int rows =
这个问题在这里已经有了答案: Python Argument Binders (7 个答案) 关闭 5 个月前。 我是 Python 和 PyQt 的新手,这是我的第一个应用程序。当前,当单击按钮时
这个问题在这里已经有了答案: Passing an argument to a slot (6 个答案) 关闭 7 年前。 我有 n 个按钮,最初都标记为“0”。这些标签,或者说值,会在程序运行的时
尝试在我的代码中继续点击按钮事件,但遇到了一些问题。 AttributeError: 'MyMainWindow' object has no attribute 'pushButton' 似乎 cl
我使用 QListWidget 创建了一个播放列表。现在我想用一个按钮保存这个列表,从今以后我可以创建或删除播放列表。另外,我怎样才能列出已保存/现有的列表。 最佳答案 使用QListWidget::
我正在创建一个程序,需要打开一个表单,然后单击按钮关闭前一个表单。我当前的问题是,当我单击按钮时,新表单显示一毫秒然后消失。 void mainMenu::on_mainLoginB_clicked(
我正在尝试构建一个 QLabel,当我按下 QPushButton 时,我希望它出现;代码很简单: void Mod28::on_pushButton_clicked() {
我有完全相同的problem ,但我将使用 QTableView 小部件。我读了this并且想知道我是否可以覆盖 createEditor 函数以使用例如 QFileDialog 来获取新数据。 如果
我在我的 uitable 中实现了各种 uimenu,但出现了一个非常烦人的行为。 function createUItable h = figure ... uimenu(h
我制作了一个读取文件的程序。我有一个读取行号的组合框:1,6,11,..等。我想例如当在组合框中选择第 1 行并单击按钮时,读取第 1-5 行(或者当第 6 行被选择时,读取第 6-10 行,结束等等
我对 PyQt 还很陌生,我正在开发一个 PyQt4 GUI,它的按钮定义如下: self.buttonFormule11=QtGui.QPushButton(self.centralwidget)
我想要一个 QPushButton,其中图像在鼠标悬停时调整大小。 以下适用于 QToolButton: QToolButton { border: 0px; } QToolButton:ho
当单击对话框中的“按钮”时,我想切换回原来的主窗口。我尝试了以下方法,它使 MainWindow 的拷贝可见,但我无法在其中编辑任何内容。请帮忙。 这是MainWindow.h #ifndef MAI
我是一名优秀的程序员,十分优秀!