First, review
1, easygui information prompt dialog box
2, easygui whether the dialog
Two, easygui other components
1, the selection dialog: choicebox (msg, title, choices)
Import EasyGUI AS G msg = " Enter your favorite color " title = " interactive games " choices = [ " red " , " green " , " blue " , " green " ] Choice = g.choicebox (msg, title, choices ) g.msgbox ( " your favorite color is: " + Choice)
2, Button dialog box: buttonbox (msg, title, choices)
Import EasyGUI AS G msg = " Enter your favorite color " title = " interactive games " choices = [ " red " , " green " , " blue " , " green " ] Choice = g.buttonbox (msg, title, choices ) g.msgbox ( " your favorite color is: " + Choice)
3, input dialog: enterbox (msg, title)
Import EasyGUI AS G text = g.enterbox ( " Please enter the word " , " title " ) g.msgbox (text)
4, a number of input dialog: multenterobx (msg, title, fields = [])
Import EasyGUI AS G name, pass_ward = g.multenterbox ( " login " , " title " , [ " account: " , " Password: " ]) Print (name) Print (pass_ward)
Third, work
1, the class exercises shining on the computer running again
2, the following is a guessing game's source code, please enter the input dialog box, print function rewritten into a gui program prompt dialog box with information
import random secret = random.randint(1, 100) print("请猜一个1到100的数,你有6次机会") success = 0 for i in range(6): guess = int(input("请猜数:")) if guess < secret: print("你猜的数太小了") elif guess > secret: print("你猜的数太大了") else: success = 1 break if success == 1: print("恭喜你,你猜对了") else: print("对不起,你猜错了,秘密数为:", secret)
四、参考答案:
import random import easygui as g secret = random.randint(1, 100) g.msgbox("请猜一个1到100的数,你有6次机会") success = 0 for i in range(6): guess = int(g.enterbox("请输入你要猜的数")) if guess < secret: g.msgbox("你猜的数太小了") elif guess > secret: g.msgbox("你猜的数太大了") else: Success = 1 BREAK IF Success == 1 : g.msgbox ( " Congratulations, you guessed it " ) the else : g.msgbox ( " I'm sorry, you guess wrong, the secret number is: " + str (Secret))