Support Forums

Full Version: My 2nd GUI-based Game
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Well I have made another "game" with TkInter, this one is a little better and less repetitive then my previous one. I got the idea from the "anagrams" game created by Sun Microsystems, it comes standard with Net Beans. The only source code I have actually taken from the original game is the word list, because I was too lazy to write my own ;). Basically it takes a random word from the list, randomly scrambles it, and you have to guess the word. Of course mine is harder then the Java version, because it randomly scrambles the word, instead of having a scrambled words list. Feel free to use this code however you like (give me some credit) and feel free to use your own word list. Here is the source
Code:
from Tkinter import *
from tkMessageBox import showinfo
import random

class game(Frame):
    def __init__(self):
        top = Tk()
        top.title('Game v2.0')
        Frame.__init__(self)
        global scrambled, guess, original
        original = '' #incase the person presses "guess" before pressing "new word"
        Label(text='Scrambled Word:').pack(side=TOP)
        scrambled = Entry()
        scrambled.pack()
        guess = Entry()
        guess.pack()
        Button(self, text='Guess', command=self.match).pack(side=LEFT)
        Button(self, text='New Word', command=self.new).pack(side=LEFT)

    def new(self): #Chooses a random word from the list, stores the original
        global scrambled, wordlist, original
        original = random.choice(wordlist)
        mixedup = self.scramble(original)
        scrambled.delete(0, END)
        scrambled.insert(0, mixedup)

    def match(self): #Matches the guess with original(unscrambled) word
        global guess, original
        if guess.get() == original:
            showinfo(title='Result', message='Correct! Try a new word.')
        else:
            showinfo(title='Result', message='Wrong! Try again')
            
    def scramble(self, string): #randomly scrambles the given string
        scrambled = ''
        used = []
        for x in range(len(string)):
            while True:
                y = random.randrange(len(string))
                if y not in used:
                    used.append(y)
                    break
            scrambled += string[y]
        if scrambled == string:
            scramble(string)
        else:
            return scrambled
#wordlist, credits goes to Sun Microsystems (Anagram game, comes standard with netbeans)
global wordlist  
wordlist = ["abstraction", "ambiguous", "arithmetic", "backslash", "bitmap",
            "circumstance", "combination","consequently","consortium",
            "decrementing","dependency","disambiguate","dynamic",
            "encapsulation","equivalent", "expression","facilitate",
            "fragment","hexadecimal","implementation","indistinguishable",
            "inheritance","internet","java","localization","microprocessor",
            "navigation","optimization","parameter","patrick","pickle",
            "polymorphic","rigorously","simultaneously","specification",
            "structure","lexical","likewise","management","manipulate",
            "mathematics","hotjava","vertex","unsigned","traditional"]

if __name__ == '__main__':
    window = game()
    window.pack()
    window.mainloop()
Of course you can look at the source to guess the words, but that is cheating Nono. Hint: All the words in the wordlist are in someway related to programming(or math).
Didn't bother making it look pretty(not that tkinter can look pretty Sad ), just liked the concept. If you have any questions about how the program works PM me, reply to this thread, or add me on msn (ub3rl33t@msn.com) Blackhat

EDIT:
Download:
Link
Click Gamev2.exe inside the folder to run the program.
Can you give us a download link?
Sure, here ya go:
Link
Click Gamev2.exe inside the folder to run the program.
Python is really hard to code in Great job
Thanks bro, looks good too.
Looks cool, downloading now.
Thanks for the program!
Good job, it's quite amazing. <3
Tkinter...

What has the world come to. D:
Looks pretty good, well done and nice share.
Pages: 1 2