📜  Python EasyGUI - 布尔框

📅  最后修改于: 2022-05-13 01:54:31.261000             🧑  作者: Mango

Python EasyGUI - 布尔框

布尔框:它用于显示一个具有多个选项的窗口,即 EasyGUI 中的按钮,它可以用于需要获取第一个选择选项的地方,因为它返回 1 用于索引为 0 的按钮和其他按钮返回0,它与索引框略有不同,下面是布尔框的样子

例子 :
在此我们将创建一个索引框,当按下任何按钮时,它将根据索引在屏幕上显示特定的消息,下面是实现

Python3
# 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 = boolbox(message, title)
 
# showing new message according to the buttons pressed
# if output is 1
if output == 1:
     
    # message / information
    message = "First Button is pressed"
     
     
# if output is 0
elif output == 0:
     
    # message / information
    message = "Button rather than first button is pressed"
     
 
# title of the window
title = "GfG - EasyGUI"
  
# creating a message box
msg = msgbox(message, title)


Python3
# 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"
 
# buttons
buttons = ["First", "Second"]
 
# creating a boolean box
output = boolbox(message, title, buttons)
 
# showing new message according to the buttons pressed
# if output is 1
if output == 1:
     
    # message / information
    message = "First Button is pressed"
     
     
# if output is 0
elif output == 0:
     
    # message / information
    message = "Button rather than first button is pressed"
     
 
# title of the window
title = "GfG - EasyGUI"
  
# creating a message box
msg = msgbox(message, title)


输出 :

另一个例子 :
在此我们将创建一个带有添加按钮的索引框,当按下任何按钮时,它将根据索引在屏幕上显示特定的消息,下面是实现

Python3

# 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"
 
# buttons
buttons = ["First", "Second"]
 
# creating a boolean box
output = boolbox(message, title, buttons)
 
# showing new message according to the buttons pressed
# if output is 1
if output == 1:
     
    # message / information
    message = "First Button is pressed"
     
     
# if output is 0
elif output == 0:
     
    # message / information
    message = "Button rather than first button is pressed"
     
 
# title of the window
title = "GfG - EasyGUI"
  
# creating a message box
msg = msgbox(message, title)
    

输出 :