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
#2
Screeny Big Grin?
Reply
#3
sure one sec


Edit:
[Image: izsyo6.jpg]


Reply
#4
Mm looks interesting, I will try it ;).
Reply
#5
Good job man. Shame I keep losing Sad
Reply
#6
(01-02-2010, 07:24 PM)Holy Wrote: Good job man. Shame I keep losing Sad
Yeah it gets kinda old after like 5 seconds. I was just testing out different functions. :p
[Image: izsyo6.jpg]


Reply
#7
Its nice, ill mite try and use your source to make my own GUI programs if ya dont mind.
Reply
#8
(01-04-2010, 03:19 AM)Fail Ninja Wrote: Its nice, ill mite try and use your source to make my own GUI programs if ya dont mind.

not at all Blackhat
[Image: izsyo6.jpg]


Reply
#9
I don't mind Tkinter, but I suggest you to start early with WX or QT, I heard wx is c0ol to use and all, but I'm using QT..
Other than that nice job!
Reply
#10
(01-05-2010, 01:30 AM)Master of The Universe Wrote: I don't mind Tkinter, but I suggest you to start early with WX or QT, I heard wx is c0ol to use and all, but I'm using QT..
Other than that nice job!

Yeah I know, every time i ask fallen for Tkinter help, he just says wxPython is better! And i agree with him, its just my book covers Tkinter, so im starting with that.
[Image: izsyo6.jpg]


Reply


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

Forum Jump:


Users browsing this thread: 2 Guest(s)