• Homework
  • Thirds
  • Upper Thirds
  • Fourth
  • Divisions
    • ICT
    • Computer Science
  • Fifth
  • Lower Sixth
  • Upper Sixth
    • Upper Sixth Theory
  • Blog
  • Careers
  • Unity
  • Networking

Using EasygGUI to talk to the user

EasyGUI is another Python module, rather like the Turtle module, that you can use in your programs to get input from the user.  It creates and displays some ready-made graphic user interface dialog boxes that you can customise.

To use it you must add 'easygui' to the import statement at the beginning of your program.

Then use the pre-made easygui functions to make dialog boxes for user interaction.
import turtle,easygui

def polygon(howmanysides):
    for i in range(howmanysides):
        turtle.forward(30)
        turtle.right(360/howmanysides)

keepgoing = True
while keepgoing:
    polygon(easygui.integerbox("How many sides"))
    keepgoing = easygui.ynbox("Do you want to keep going?")

turtle.exitonclick()

Examples of EasyGUI boxes

Button Box

Picture
The button box will display a row of buttons with text that you decide.

import turtle,easygui

def polygon(howmanysides):
    for i in range(howmanysides):
        turtle.forward(30)
        turtle.right(360/howmanysides)

result = easygui.buttonbox("Choose your shape",choices=("Hexagon","Octagon","Square"))
if result == "Hexagon":
    polygon(6)
if result == "Octagon":
    polygon(8)
if result == "Square":
    polygon(4)

turtle.exitonclick()



Password Box

The password box pops-up a dialog box but when the user enters something the text is replaced by stars - as in a password field
Picture
import turtle,easygui

def polygon(howmanysides):
    for i in range(howmanysides):
        turtle.forward(30)
        turtle.right(360/howmanysides)

result = easygui.passwordbox("Enter the secret code word")
if result == "secret":
    polygon(20)
else:
    easygui.msgbox("Access denied!")

turtle.exitonclick()

Message Box

The message box was used in the example above.  It pops-up a message of your choice, with an OK button.
Picture

More EasyGUI information here
Powered by Create your own unique website with customizable templates.