#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2013
    Posts
    12
    Rep Power
    0

    Is it possible to create a GUI for python code?


    Im very new to python programming, i only know a small bit of javascript and visual basic. i apologize if this is a very stupid question, but i was wondering if it is possible to create a GUI for python code?
  2. #2
  3. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,966
    Rep Power
    481
    Oh yes, it's possible.

    Most programming languages provide the means to invoke code written in some other language. Python is particularly good at tying languages together. If you can write it in one language, you can run it in python. Python is a general purpose programming language. If the program can be written it can be written in python.
    [code]Code tags[/code] are essential for python code and Makefiles!
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2013
    Posts
    12
    Rep Power
    0
    thanks! would you be willing to give me some examples of how you would use python to tie languages together?
  6. #4
  7. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2013
    Location
    Pennsylvania, USA
    Posts
    35
    Rep Power
    2
    Originally Posted by timboslice
    thanks! would you be willing to give me some examples of how you would use python to tie languages together?
    You can even use Pygame to create a GUI. There are other toolkits available also.

    Try on youtube, "/watch?v=8TcrTTXPD7s".
  8. #5
  9. Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2005
    Posts
    618
    Rep Power
    65
    An example of code for the Python Tkinter GUI toolkit (normally part of your Python installation) ...
    Code:
    ''' tk_Listbox_select1.py
    get the value of a selected item in a Tkinter listbox
    (the TCL based Tkinter GUI toolkit comes with Python)
    will work with version 2 or 3 of Python
    '''
    
    try:
        # Python2
        import Tkinter as tk
    except ImportError:
        # Python3
        import tkinter as tk
    
    def on_click_listbox(event):
        # get selected line index
        index = listbox.curselection()
        # get the line's text with listbox.get(index)
        # and format an output string
        seltext = "You selected {}".format(listbox.get(index))
        # show formatted text in label
        label.configure(text=seltext)
    
    # create the main or root window
    root = tk.Tk()
    
    # create a typical listbox, make background yellow
    listbox = tk.Listbox(root, width=20, height=7, bg="yellow")
    # use pack layout manager
    listbox.pack()
    
    mylist = ['green', 'blue', 'red', 'gold', 'pink']
    # load the listbox witt the contents of the list
    for color in mylist:
        listbox.insert('end', color)
    
    # create a label used for info and result output
    label = tk.Label(root, text='click color to select', width=20)
    # this puts the label below the listbox
    label.pack()
    
    # use left mouse click on a listbox item to display selection
    listbox.bind('<ButtonRelease-1>', on_click_listbox)
    
    # now start the GUI event loop
    root.mainloop()
    The nice thing about Tkinter is the small footprint and its relatively simple syntax. It will teach you the basics of GUI programming. From there you can create your own classes to add more power. More recent Python versions also add the Tkinter Tile kit "ttk" with additional widgets and styling.
    Last edited by Dietrich; September 17th, 2013 at 12:14 PM.
    Real Programmers always confuse Christmas and Halloween because Oct31 == Dec25
  10. #6
  11. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,966
    Rep Power
    481
    [code]Code tags[/code] are essential for python code and Makefiles!

IMN logo majestic logo threadwatch logo seochat tools logo