Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
My first GUI
#1
Well here is my first GUI(gooey :p). It's a "game" technically speaking , although a really crappy game. Just testing out buttons and updating Entry fields. It isn't very neat and well I think I did some unnecessary things, but I just wanted to make sure it would work. Basically you press one of three buttons, and after you press a button, the round changes, and you money either goes up 100 or down 100 whether you win or lose. Pretty stupid but again, I was testing things out.

Code:
from Tkinter import *
from tkMessageBox import showinfo
import random

money = 0
round = 0

class gooey(Frame):
    def __init__(self, parent=None):
        global money
        global e
        global r
        global round
        Frame.__init__(self, parent)
        Label(text='Money').pack(side=BOTTOM)
        e = Entry(money)
        e.pack(side=BOTTOM)
        Label(text='Round').pack(side=BOTTOM)
        r = Entry(round)
        r.pack(side=BOTTOM)
        button1 = Button(self, text='Press me', command=self.btn1)
        button1.pack()
        button2 = Button(self, text='Press me', command=self.btn2)
        button2.pack(side=RIGHT)
        button3 = Button(self, text='Press me', command=self.btn3)
        button3.pack(side=LEFT)
    def btn1(self):
        global money
        global e
        global r
        global round
        a = 'You win, Congrats!'
        b = 'You lose, Sorry :('
        c = [a , b]
        d = random.choice(c)
        showinfo(title='Result', message=d)
        if d==a:
            money += 100
            e.delete(0, END)
            e.insert(0, money)
            round += 1
            r.delete(0, END)
            r.insert(0, round)
            self
        if d==b:
            money -=100
            e.delete(0, END)
            e.insert(0,  money)
            round +=1
            r.delete(0, END)
            r.insert(0, round)
            self
                    
    def btn2(self):
        global money
        global e
        global r
        global round
        a = 'You win, Congrats!'
        b = 'You lose, Sorry :('
        c = [a , b]
        d = random.choice(c)
        showinfo(title='Result', message=d)
        if d==a:
            money += 100
            e.delete(0, END)
            e.insert(0, money)
            round += 1
            r.delete(0, END)
            r.insert(0, round)
            self
        if d==b:
            money -=100
            e.delete(0, END)
            e.insert(0,  money)
            round += 1
            r.delete(0, END)
            r.insert(0,  round)
            self

                    
    def btn3(self):
        global money
        global e
        global r
        global round
        a = 'You win, Congrats!'
        b = 'You lose, Sorry :('
        c = [a , b]
        d = random.choice(c)
        showinfo(title='Result', message=d)
        if d==a:
            money += 100
            e.delete(0, END)
            e.insert(0,  money)
            round += 1
            r.delete(0, END)
            r.insert(0,  round)
            self
        if d==b:
            money -=100
            e.delete(0, END)
            e.insert(0,  money)
            round += 1
            r.delete(0, END)
            r.insert(0,  round)
            self

        
if __name__ == '__main__':
    window = gooey()
    window.pack()
    window.mainloop()
If there is anything I can do to make the code neater or shorter please tell me as I am new at GUI's and Classes. If there is anything I can do to improve the "game" please let me know. Enjoy Blackhat

EDIT: fixed some errors in the source code.
[Image: izsyo6.jpg]


Reply


Messages In This Thread
My first GUI - by uber1337 - 01-02-2010, 02:22 PM
RE: My first GUI - by Zomaian - 01-02-2010, 02:26 PM
RE: My first GUI - by uber1337 - 01-02-2010, 02:28 PM
RE: My first GUI - by Zomaian - 01-02-2010, 03:06 PM
RE: My first GUI - by Zoidberg - 01-02-2010, 07:24 PM
RE: My first GUI - by uber1337 - 01-02-2010, 07:27 PM
RE: My first GUI - by Yoshi - 01-04-2010, 03:19 AM
RE: My first GUI - by uber1337 - 01-04-2010, 06:26 PM
RE: My first GUI - by Gaijin - 01-05-2010, 01:30 AM
RE: My first GUI - by uber1337 - 01-05-2010, 04:15 PM
RE: My first GUI - by Gaijin - 01-06-2010, 02:27 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  My 2nd GUI-based Game uber1337 10 2,114 12-06-2010, 03:31 PM
Last Post: xerotic
  My First GUI Game "Falling Squares" nevets04 19 4,682 04-11-2010, 03:39 AM
Last Post: Don Panzer

Forum Jump:


Users browsing this thread: 6 Guest(s)