📜  Python EasyGUI 模块 - 简介

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

Python EasyGUI 模块 - 简介

EasyGUI是一个用于Python中非常简单、非常容易的 GUI 编程的模块。 EasyGUI 与其他 GUI 生成器的不同之处在于 EasyGUI 不是事件驱动的。相反,所有 GUI 交互都由简单的函数调用调用。与其他复杂的 GUI 不同,EasyGUI 是迄今为止最简单的 GUI。

使用以下命令安装:

pip install easygui

注意:不建议在 IDLE 上运行 EasyGui,因为 EasyGui 在 Tkinter 上运行并且有自己的事件循环,IDLE 也是 Tkinter 模块编写的应用程序,它也有自己的事件循环。因此,当两者同时运行时,可能会发生冲突,并且可能会出现不可预知的结果。所以最好在 IDLE 之外运行 EasyGui。

导入 EasyGUI

from easygui import *

这是无需额外参考即可使用所有小部件的最佳方式。

例子 :
在此我们将创建一个窗口,其中包含一条短消息和一个按下按钮,按下该按钮会关闭我们的消息框,下面是实现

Python3
# importing easygui module
from easygui import *
 
# title of our window
title = "GfG-EasyGUI"
 
# message for our window
msg = "GeeksforGeeks, Hello World from EasyGUI"
 
# button message by default it is "OK"
button = "Let's Go"
 
# creating a message box
msgbox(msg, title, button )


Python3
# importing easygui module
from easygui import *
 
# choices which user can select
choices = ["Geek", "Super Geek", "Super Geek 2", "Super Geek God"]
 
# message / question to be asked
msg = "Select any one option"
 
# opening a choice box using our msg and choices
reply = choicebox(msg, choices = choices)
 
# printing the selected option
print("You selected : ", end = "")
print(reply)


输出 :

"Let's Go"

另一个例子:
In this we will allow user to choose the “geek form” and when ans is selected it will get printed, below is the implementation

Python3

# importing easygui module
from easygui import *
 
# choices which user can select
choices = ["Geek", "Super Geek", "Super Geek 2", "Super Geek God"]
 
# message / question to be asked
msg = "Select any one option"
 
# opening a choice box using our msg and choices
reply = choicebox(msg, choices = choices)
 
# printing the selected option
print("You selected : ", end = "")
print(reply)

输出 :

You selected : Super Geek God