Jump to content

GUI and a confused person


Zimmer
 Share

Recommended Posts

I have been learning and writing python applications for awhile now and over time have tried to learn a GUI toolkit. Having tried several I have always ended up confused, bewildered, and frustrated. Is it just me, is it that python isn't meant for GUIs? I would like to here your thoughts. Am I just someone doomed to command line applications? Should I try a new language for creating GUIs? Has anyone else had this type of problem (trying to create GUI programs)? Thanks for you input.

Link to comment
Share on other sites

Well there's always Visual Studio with Windows forms applications and toolbox with drag and drop form controls.

Though with your experience with python I doubt you'd want to learn how to program for Windows only. Anyone else got a better idea? I'm actually interested myself in this. Something like VS that could be used to develop cross-platform applications.

Link to comment
Share on other sites

Thanks for the reply I have actually been thinking about maybe C++ but I doubt that would be any easier for GUI's. Then again I could still use python and just you VB as a shell hmm. The reply is much appreciated.

Link to comment
Share on other sites

Writing a GUI in Java is more than easy:

import javax.swing.jframe;
import javax.swing.jbutton;

public void magicFrame() {
  jframe tehFrame = new jframe("Window in Java");
  tehFrame.add(new jbutton("This is a button"));
  tehFrame.pack();
  tehFrame.setvisible(true);
}

Some thing like that? Makes a window that has a button inside it.

Link to comment
Share on other sites

Check out tkinter, from what I remember when I was using it it was quite easy to learn. I haven't used it in so long though - don't do very much GUI programming.

from Tkinter import *
root=Tk()
myString=StringVar()
Label(root,textvariable=myString).pack()
myString.set("Well, eh, how about a little red Leicester.")
def changeLabel():
    myString.set("I'm, a-fraid we're fresh out of red Leicester, sir. ")
Button(root,text='Click Me',command=changeLabel).pack()
root.mainloop()

Source

Link to comment
Share on other sites

Have you tried gtk? It always seemed like the easiest to me.

Here's a simple window with a kill function so the program exits properly when the window is closed.

import gtk, sys

def gtkwindow():
    def kill(window):
        window.destroy()
        sys.exit()       
    window = gtk.Window()
    width, height = 250,200
    window.resize(width, height)
    window.show()
    window.connect('destroy',kill)    
    gtk.main()

gtkwindow()

Link to comment
Share on other sites

I agree with [ratmandall], gtk is definitely the way to go. You should also check into Glade, it can build an XML file that describes your GUI and that gets loaded at runtime.

#!/usr/bin/env python

import sys
try:
    import pygtk
    pygtk.require("2.0")
except:
    pass

try:
    import gtk
    import gtk.glade
except:
    sys.exit(1)

class pyGUI:
    """ Main class for pyGUI application """
    def __init__(self):
        self.wTree = gtk.glade.XML("dialog.glade")

        # Build our dictionary and connect it
        dic = { "on_ButtonClose_clicked": self.ActionClose,
                "on_DialogMain_destroy": gtk.main_quit }
        self.wTree.signal_autoconnect(dic)

    def ActionClose(self, widget):
        gtk.main_quit()

if __name__ == '__main__':
    app = pyGUI()
    gtk.main()

I have been learning and writing python applications for awhile now and over time have tried to learn a GUI toolkit. Having tried several I have always ended up confused, bewildered, and frustrated. Is it just me, is it that python isn't meant for GUIs? I would like to here your thoughts. Am I just someone doomed to command line applications? Should I try a new language for creating GUIs? Has anyone else had this type of problem (trying to create GUI programs)? Thanks for you input.
Link to comment
Share on other sites

I have not been coding in python for long, but my friend has and I asked him about your question. He said that python is more of a command line language. The most gui you will get out of it is if compile it and stuff like that in programs like xcode. Well, good luck with your gui.

cheers,

Destro

Link to comment
Share on other sites

Writing a GUI in Java is more than easy:

import javax.swing.jframe;
import javax.swing.jbutton;

public void magicFrame() {
  jframe tehFrame = new jframe("Window in Java");
  tehFrame.add(new jbutton("This is a button"));
  tehFrame.pack();
  tehFrame.setvisible(true);
}

Some thing like that? Makes a window that has a button inside it.

And for a free IDE, try Netbeans. WHich can be set up to work with PHP/Python/C/C++ etc etc, but specialises in java.

As for pyton being no use for GUI, i'd have to say use WxWindows. For an example of what can be achived, just take a look at a program featured on the show. Inkscape.

Inkscape was written in Python using the WxWindows toolkit.

Cheers

Shawty

Link to comment
Share on other sites

@Destro Thanks for that, I believe I heard that from somewhere but hearing it from a second source helps.

Shawty ya I'll probably look into java or VB, VB C++, or VB C#. It seems that I can easily integrate the command line python apps by compiling the exe with a .pyw extensions so their are no black boxes to free users out. Also for python I can just return the data using sys.exit(i) and have the gui use it. Also thanks everyone for giving you insights, help, and experience it is much appreciated. Thanks again.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...