Python EasyGUI - 选择框
选择框:用于在EasyGUI中显示一个具有多个选项的窗口,即项目,它可以用于需要在一组项目中选择任何一个项目,它由标题、要显示的消息、组项目和一对“确定”、“取消”按钮来确认项目的选择。下面是选择框的样子
In order to do this we will use choicebox
method
Syntax : choicebox(message, title, choices)
Argument : It takes 3 arguments, first string i.e message/information to be displayed, second string i.e title of the window and third is list of strings i.e items
Return : It returns return the display text of the selected item else None
例子 :
在此我们将创建一个包含多个项目的选择框,当任何项目被确认时,它将根据项目在屏幕上显示特定的消息,下面是实现
# importing easygui module
from easygui import *
# message to be displayed
text = "Selected any one item"
# window title
title = "Window Title GfG"
# item choices
choices = ["Geek", "Super Geeek", "Super Geek 2", "Super Geek God"]
# creating a button box
output = choicebox(text, title, choices)
# title for the message box
title = "Message Box"
# message
message = "You selected : " + str(output)
# creating a message box
msg = msgbox(message, title)
输出 :
另一个例子 :
在此我们将创建一个不添加任何项目的选择框,当任何项目被确认时,它将根据项目在屏幕上显示特定的消息,下面是实现
# importing easygui module
from easygui import *
# message to be displayed
text = "Selected any one item"
# window title
title = "Window Title GfG"
# creating a button box
output = choicebox(text, title)
# title for the message box
title = "Message Box"
# message
message = "You selected : " + str(output)
# creating a message box
msg = msgbox(message, title)
输出 :