Python 7 Levels, L1, Unit 8, GUI Design II

Powered By EmbedPress

Exercise 1:

import easygui as g
flavor = g.buttonbox("Please pick your flavor",title = "Icecream Order System",
            choices = ("Milk","Vanilla","Strawberry","Matcha"),image = "./ice.gif")
g.msgbox("You picked "+flavor+" flavor ",title = "Icecream Order System",image = "./ice.gif")

Exercise 2:

import easygui as g
number= g.choicebox("Please choose a lucky number",title= "Lucky number",choices= ("0","1","2","3","4","5","6","7","8","9"))
g.msgbox("What you selected is "+number,title= "Lucky number")

Exercise 3:

import easygui as g
flavor= g.enterbox("Please enter your favorite flavor",title= "Ice cream ordering system")
g.msgbox("What you entered is "+flavor+" taste",title= "Ice cream ordering system")

Exercise 4:

import easygui as g
num = g.enterbox("Please input an integer",title = "test")
number = int(num)
g.msgbox(msg ="You input: "+number)#you will get an error here

Exercise 5:

import easygui as g
score= g.integerbox("Please enter your score",title= "Achievements",lowerbound= 0,upperbound= 100)
g.msgbox("your score is "+str(score))

Exercise 6:

import easygui as g
g.multpasswordbox("Enter username and password",title= "User login interface",fields= ("username","password"))

Homework:

import easygui as g
name = g.enterbox("Please input your name:")
adress = g.enterbox("Please input your address")
tell = g.enterbox("Please input your contact information")
g.msgbox(name+"\n"+adress+"\n"+tell,title = "Delivery Information",ok_button = "Confirm")

Guess Number Game:

import random as r
import easygui as g
secret= r.randint(1,100)
g.msgbox("The computer randomly generated a number ranged 1~100. Please guess this number",title= "Guess number game")
number= g.integerbox("Please enter the number you guess")
while number!= secret:
    if number> secret:
        g.msgbox("Your guess is too high, please continue guessing")
        number= g.integerbox("Please enter the number you want to guess")
    else :
        g.msgbox("Your guess is too small, please continue guessing")
        number= g.integerbox("Please enter the number you want to guess")
g.msgbox("Congratulations, you guessed it correctly. The number randomly generated by the computer is "+(str(secret)))

dahan1999

1 Comment

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Posts