Python EasyGUI - 索引框
索引框:用于在 EasyGUI 中显示具有多个选项的窗口,即按钮,可用于需要获取用户选择的选项的地方。它类似于按钮框,但用于按钮具有相同名称的地方,它根据它的索引指定选定的按钮。按钮的索引从 0 开始,下面是索引框的样子
In order to do this we will use indexbox
method
Syntax : indexbox(message, title, buttons)
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 buttons
Return : It returns return of the index selected by the user
例子 :
在此我们将创建一个带有添加按钮的索引框,当按下任何按钮时,它将根据索引在屏幕上显示特定的消息,下面是实现
# importing easygui module
from easygui import *
# message / information to be displayed on the screen
message = "Select any one button"
# title of the window
title = "GfG - EasyGUI"
# list of buttons
buttons = ["First", "Second", "Third", "Fourth"]
# creating a index box
output = indexbox(message, title, buttons)
# showing new message according to the buttons pressed
# if index is 0
if output == 0:
# message / information
message = "First"
# if index is 1
elif output == 1:
# message / information
message = "Second"
# if index is 2
elif output == 2:
# message / information
message = "Third"
# if index is 3
elif output == 3:
# message / information
message = "Fourth"
# message
message = message + " Button Pressed"
# title of the window
title = "GfG - EasyGUI"
# creating a message box
msg = msgbox(message, title)
输出 :
另一个例子 :
在此我们将创建一个不设置任何按钮的索引框,当按下任何按钮时,它将根据索引在屏幕上显示特定的消息,下面是实现
# importing easygui module
from easygui import *
# message / information to be displayed on the screen
message = "Select any one button"
# title of the window
title = "GfG - EasyGUI"
# creating a index box
output = indexbox(message, title)
# showing new message according to the buttons pressed
# if index is 0
if output == 0:
# message / information
message = "First"
# if index is 1
elif output == 1:
# message / information
message = "Second"
# message
message = message + " Button Pressed"
# title of the window
title = "GfG - EasyGUI"
# creating a message box
msg = msgbox(message, title)
输出 :