Python integration Tester Based on Tkinter

Source: Internet
Author: User

Preliminary discussion:

I still remember that eight years ago, when I was in the eighth grade, I was very handsome ..

Name fight is still a hot game ..

Suddenly, I used Tkinter to do this .. .. Very frustrated, but programming is free, just how to compile it ..

Changed the name to the marriage tester ..

In fact, it is really boring, that is, to consolidate Tkinter .. No .. Don't worry ..



Algorithm
MD5 + whether the mod 3 can be done, two people can do the mod, that is the most embarrassing, only one person mod 3 to do, it will make up, if all mod is not, it may not be suitable. Why is it 3? Do you think that many things in the world are related to 3? A lot of time intervals are three seconds. If it is more, it will be longer. If it is less, it will be shorter. In addition, this person has a great relationship with 3 people .. In the family ..



Long Look





Code

#-*-Coding: UTF-8-*-from Tkinter import * from ttk import Frame, Button, Style, Entry, Labelimport tkMessageBox import reimport urllib, Queue, sgmllibimport timeimport threadingimport tkFileDialogimport randomimport hashlibclass NameFighter (Frame): txt = "" area = None en1 = None en2 = None def _ init _ (self, parent): Frame. _ init _ (self, parent) self. parent = parent self. initUI () # event binding, used to display text self in real time. parent. bind ("<>", lambda evt: self.area.insert(END,self.txt) # bind the event to let Text track the latest line of self. parent. bind ("<
 
  
> ", Lambda evt: self. area. see (END) # bind the event to restore goBtn to normal self. parent. bind (" <
  
   
> ", Lambda evt: self. goBtn. config (state = NORMAL) def do_figting (self, moves, n1, n2, b1, b2): try: self.txt = "if the two can continue for a long time, the more stable love is! \ N "self. parent. event_generate (" <> ", when =" tail ") # Trigger the bind event, that is, display the text self. parent. event_generate (" <
   
    
> ", When =" tail ") # Trigger the bind event, that is, display text time. sleep (1) for I in range (5, 0,-1): self.txt = "Countdown:" + str (I) + "seconds! \ N "self. parent. event_generate (" <> ", when =" tail ") # Trigger the bind event, that is, display the text self. parent. event_generate (" <
    
     
> ", When =" tail ") # Trigger the bind event, that is, display text time. sleep (1) self.txt = n1 + "initial blood volume:" + str (b1) + "\ n" + n2 + "initial blood volume:" + str (b2) + "\ n" self. parent. event_generate ("<>", when = "tail") # Trigger the bind event, that is, display the text time. sleep (1) flag = 1 while b1> 0 and b2> 0: self.txt = "\ n ============================" + str (flag) + "Wheel ===================================\ n" self. parent. event_generate ("<>", when = "tail") # Trigger the bind event, that is, display the text self. parent. event_generate ("<
     
      
> ", When =" tail ") # Trigger the bind event, that is, display text time. sleep (1) tempb = random. randint (300,400) tempm = random. randint (0, len (moves)-1) if flag % 2 = 0: b2-= tempb if b2 <0: self.txt = n2 + "overwhelmed, killed by "+ n1 +" live... \ n "else: self.txt = n1 +" "+ moves [tempm] +" "+ n2 +" cause "+ str (tempb) +! "Self.txt + = n2 +" remaining blood volume: "+ str (b2) +" \ n "else: b1-= tempb if b1 <0: self.txt = n1 +" overwhelmed, killed by "+ n2 +" living... \ n "else: self.txt = n2 +" "+ moves [tempm] +" "+ n1 +" cause "+ str (tempb) +! "Self.txt + = n1 +" remaining blood volume: "+ str (b1) +" \ n "flag + = 1 self. parent. event_generate ("<>", when = "tail") # Trigger the bind event, that is, display the text self. parent. event_generate ("<
      
        > ", When =" tail ") # Trigger the bind event, that is, display text time. sleep (1.5) self.txt = "\ n =============================== everything is over ============ =================\ n "self. parent. event_generate ("<>", when = "tail") # Trigger the bind event, that is, display the text self. parent. event_generate ("<
       
         > ", When =" tail ") # Trigger the bind event, that is, display text time. sleep (1) # True logic, with 3 as the benchmark if b1 % 3 = 0 and b2 % 3 = 0: self.txt = "congratulations" + n1 + "and" + n2 + "! You are very suitable to be together! \ N "elif b1 % 3 = 0 or b2 % 3 = 0: self.txt =" congratulations "+ n1 +" and "+ n2 + "! Because one person is more accommodating, you are more suitable to be together! \ N "else: self.txt ="! "+ N1 +" and "+ n2 + "! Seems inappropriate? Don't want to say anything! \ N "self. parent. event_generate (" <> ", when =" tail ") # Trigger the bind event, that is, display the text self. parent. event_generate (" <
        
          > ", When =" tail ") # Trigger the bind event, that is, display the text finally: self. parent. event_generate (" <
         
           > ", When =" tail ") # Trigger the bind event so that goBtn restores def onGo (self): maleName = self. en1.get () famaleName = self. en2.get () n1 = maleName. encode ("utf8") n2 = famaleName. encode ("utf8") md5_1 = hashlib. md5 () md5_1.update (n1) md5_1 = md5_1.hexdigest (). upper () md5_2 = hashlib. md5 () md5_2.update (str (n2) md5_2 = md5_2.hexdigest (). upper () blood_1 = 0 for I in range (len (md5_1): blood_1 + = ord (md5_1 [I]) print blood_1 blood _ 2 = 0 for I in range (len (md5_2): blood_2 + = ord (md5_2 [I]) print blood_2 if maleName = "" or famaleName = "": tkMessageBox. showinfo ', 'scratched it. ', 'Let out the infinite hitting of the sea.', 'lick it.', and 'yell.'] self. goBtn. config (state = DISABLED) # first set to disabled do_figting_thread = threading. thread (target = self. do_figting, args = (moves, n1, n2, blood_1, blood_2,) do_figting_thread.start () def OnHelp (self): tkMessageBox. showinfo ('play', 'just a few clicks, even the funny ratio will play \ n') def initUI (self): # size, position w = 600 h = 400 sw = self. parent. winfo_screenwidth () sh = self. parent. winfo_screenheight () x = (sw-w)/2 y = (sh-h)/2 self. parent. geometry ('% dx % d + % d' % (w, h, x, y) self. parent. title ("presented by Harbin Majiagou men's Vocational and Technical College! Computer fortune teller-marriage tester ") # style self. style = Style () self. style. theme_use ("default") Style (). configure ("TButton", padding = (0, 5, 0, 5), font = 'serif 10') # Control Position Control self. columnconfigure (1, weight = 1) self. columnconfigure (2, pad = 7) self. rowconfigure (3, weight = 1) self. rowconfigure (5, pad = 7) # Label lb1 = Label (self, text = "Enter the male name:") lb1.grid (row = 0, column = 0, sticky = W) lb2 = Label (self, text = "Enter the female name :") Lb2.grid (row = 1, column = 0, sticky = W) # input Entry self. en1 = Entry (self) self. en1.grid (row = 0, column = 1, columnspan = 1, sticky = W + E) self. en2 = Entry (self) self. en2.grid (row = 1, column = 1, columnspan = 1, sticky = W + E) # display text & Scrollbar self. area = Text (self, bg = 'black', fg = 'green') self. area. grid (row = 2, column = 0, columnspan = 2, rowspan = 4, sticky = E + W + S + N) self. area. see (1 000.0) self. sb = Scrollbar (self) self. sb. grid (row = 2, column = 1, rowspan = 4, sticky = E + W + S + N) self. area ['yscrollcommand'] = self. sb. set # text goes down to trigger the set () self of scrollbar. sb ['command'] = self. area. yview # Drag the scrollbar to trigger the view movement of text # Go button self. goBtn = Button (self, text = "Go! ", Command = self. onGo) self. goBtn. grid (row = 0, column = 2) lb3 = Label (self, text = "computer fortune teller-absolutely accurate, made by ouyang! ") Lb3.grid (row = 6, column = 1, sticky = E) # Help Button helpBtn = Button (self, text =" how to play? ", Command = self. onHelp) helpBtn. grid (row = 6, column = 2) # bind self. pack (fill = BOTH, expand = 1) def main (): root = Tk () root. geometry ("250x150 + 300 + 300") app = NameFighter (root) root. mainloop () if _ name _ = '_ main _': main ()
         
        
       
      
     
    
   
  
 


Important


Event binding and triggering

When an event is triggered, it is best to put the event in tail, otherwise it will be easy to mess up... When = "tail"




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.