Python3.3 use tkinter to guess the digital game code

Source: Internet
Author: User

Release date: Edit: www.jbxue.com original address: Workshop. In this section, I will share the code for tkinter to develop a quiz game in ython3.3.

Example: tkinter instance in python3.3.
 

Sample Code for copying code:

#-*-Coding: UTF-8 -*-
Import tkinter as tk
Import sys
Import random
Import re
Number = random. randint (0,1024)
Running = True
Num = 0
Nmaxn= 1024
Nminn = 0
Def eBtnClose (event ):
Root. destroy ()

Def eBtnGuess (event ):
Global nmaxn
Global nminn
Global num
Global running
# Modify the defect: the user is correct, and the prompt "Edit by Hongten 2013-09-09" is displayed.
# That is, after the user is correct, the prompt tag should not change as the user clicks the "Guess" button.
If running:
Val_a = int (entry_a.get ())
If val_a = number:
Labelqval ("Congratulations! ")
Num + = 1
Running = False
NumGuess ()
Elif val_a <number:
If val_a> nminn:
Nminn = val_a
Num + = 1
Label_tip_min.config (label_tip_min, text = nminn)
Labelqval ("small ")
Else:
If val_a <nmaxn:
Nmaxn = val_a
Num + = 1
Label_tip_max.config (label_tip_max, text = nmaxn)
Labelqval ("big ")
Else:
Labelqval ('you are correct ...')
Def numGuess ():
If num = 1:
Labelqval ('depend on me! One answer! ')
Elif num <10:
Labelqval ('= within 10 times, the correct answer is awesome... Number of attempts: '+ str (num ))
Elif num <50:
Labelqval ('Okay. Number of attempts: '+ str (num ))
Else:
Labelqval ('Okay ..... You have tried more than 50 times .... Number of attempts: '+ str (num ))

Def labelqval (vText ):
Label_val_q.config (label_val_q, text = vText)

Root = tk. Tk (className = "game by size ")
Root. geometry ("400x90 + 200 + 200 ")
Line_a_tip = tk. Frame (root)
Label_tip_max = tk. Label (line_a_tip, text = nmaxn)
Label_tip_min = tk. Label (line_a_tip, text = nminn)
Label_tip_max.pack (side = "top", fill = "x ")
Label_tip_min.pack (side = "bottom", fill = "x ")
Line_a_tip.pack (side = "left", fill = "y ")
Line_question = tk. Frame (root)
Label_val_q = tk. Label (line_question, width = "80 ")
Label_val_q.pack (side = "left ")
Line_question.pack (side = "top", fill = "x ")
Line_input = tk. Frame (root)
Entry_a = tk. Entry (line_input, width = "40 ")
BtnGuess = tk. Button (line_input, text = "Guess ")
Entry_a.pack (side = "left ")
Entry_a.bind ('<Return>', eBtnGuess)
BtnGuess. bind ('<Button-1>', eBtnGuess)
BtnGuess. pack (side = "left ")
Line_input.pack (side = "top", fill = "x ")

Line_btn = tk. Frame (root)
BtnClose = tk. Button (line_btn, text = "close ")
BtnClose. bind ('<Button-1>', eBtnClose)
BtnClose. pack (side = "left ")
Line_btn.pack (side = "top ")
Labelqval ("enter any integer between 0 and 1024 :")
Entry_a.focus_set ()
Print (number)
Root. mainloop ()

Articles you may be interested in:
  • Python puzzle game computing tower example tutorial
  • Python wenquxing guess digital game instance code tutorial
  • Example of using python to guess digital games (with no repeated numbers)
  • Python snake game instance code
  • Python sample code
  • Implementation Code of python Q & A games

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.