Support Forums
My first GUI - Printable Version

+- Support Forums (https://www.supportforums.net)
+-- Forum: Categories (https://www.supportforums.net/forumdisplay.php?fid=87)
+--- Forum: Coding Support Forums (https://www.supportforums.net/forumdisplay.php?fid=18)
+---- Forum: Python Programming Language (https://www.supportforums.net/forumdisplay.php?fid=32)
+---- Thread: My first GUI (/showthread.php?tid=4138)

Pages: 1 2


My first GUI - uber1337 - 01-02-2010

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.


RE: My first GUI - Zomaian - 01-02-2010

Screeny Big Grin?


RE: My first GUI - uber1337 - 01-02-2010

sure one sec


Edit:



RE: My first GUI - Zomaian - 01-02-2010

Mm looks interesting, I will try it ;).


RE: My first GUI - Zoidberg - 01-02-2010

Good job man. Shame I keep losing Sad


RE: My first GUI - uber1337 - 01-02-2010

(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


RE: My first GUI - Yoshi - 01-04-2010

Its nice, ill mite try and use your source to make my own GUI programs if ya dont mind.


RE: My first GUI - uber1337 - 01-04-2010

(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


RE: My first GUI - Gaijin - 01-05-2010

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!


RE: My first GUI - uber1337 - 01-05-2010

(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.