Python EasyGUI - 按钮框
EasyGUI是一个用于Python中非常简单、非常容易的 GUI 编程的模块。 EasyGUI 与其他 GUI 生成器的不同之处在于 EasyGUI 不是事件驱动的。相反,所有 GUI 交互都由简单的函数调用调用。与其他复杂的 GUI 不同,EasyGUI 是迄今为止最简单的 GUI。
按钮框:用于在 EasyGUI 中显示一个有多个按钮的窗口,它可以用于有条件从众多按钮中选择一个按钮,例如电梯中的按钮一次用户只能选择一个选项,下面是如何普通按钮框看起来像
In order to do this we will use buttonbox
method
Syntax : buttonbox(text, title, button_list)
Argument : It takes 3 arguments, first string i.e text to be displayed, second string i.e title of the window and third list of button(strings)
Return : It returns the text of the button that the user selected
例子 :
在此我们将创建一个按钮框窗口,其中包含三个用户可以选择的按钮,并且选定的按钮文本将被打印出来,下面是实现
# importing easygui module
from easygui import *
# message to be displayed
text = "Message to be displayed on the window GfG"
# window title
title = "Window Title GfG"
# button list
button_list = []
# button 1
button1 = "First"
# second button
button2 = "Second"
# third button
button3 = "Third"
# appending button to the button list
button_list.append(button1)
button_list.append(button2)
button_list.append(button3)
# creating a button box
output = buttonbox(text, title, button_list)
# printing the button pressed by the user
print("User selected option : ", end = " ")
print(output)
输出 :
User selected option : Second
另一个例子 :
# importing easygui module
from easygui import *
# message to be displayed
text = "Message to be displayed on the window GfG"
# window title
title = "Window Title GfG"
# creating a button box
output = buttonbox(text, title)
# printing the button pressed by the user
print("User selected option : ", end = " ")
print(output)
输出 :
User selected option : Button[3]