954,557 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Version 3 GUI Toolkits

I use python for various personal projects and hobby stuff. I do mostly command line stuff, just cuz I don't need the gui for a lot of it.

I would like to start moving on to GUIs, but I have run into a problem. I started with Python v3. All the toolkits, WYSIWYG designers, etc are all for version 2.

Is there a toolkit and (hopefully) a WYSIWYG designer for Python 3?

toadzky
Junior Poster in Training
96 posts since Mar 2007
Reputation Points: 10
Solved Threads: 0
 

For python 3 there is PyQt
Comes with Qt designer

Look at Ene Uran post about qt-designer.
http://www.daniweb.com/forums/thread191210-10.html

snippsat
Practically a Posting Shark
808 posts since Aug 2008
Reputation Points: 353
Solved Threads: 294
 

You cannot distribute Qt software on Windows without a license.

ultimatebuster
Posting Whiz in Training
250 posts since Mar 2010
Reputation Points: 24
Solved Threads: 69
 
You cannot distribute Qt software on Windows without a license.

Really meant for commercial software only.

vegaseat
DaniWeb's Hypocrite
Moderator
5,989 posts since Oct 2004
Reputation Points: 1,345
Solved Threads: 1,417
 

The problem with designer programs is that they create rather bloated code.

Most seasoned GUI programmers prefer a template approach. The Tkinter GUI toolkit has been updated with the release of Python version 3.1 and now contains the extra widgets that come with the tile extension ttk.

vegaseat
DaniWeb's Hypocrite
Moderator
5,989 posts since Oct 2004
Reputation Points: 1,345
Solved Threads: 1,417
 

I've never really done GUIs in python. I usually use C# .NET for GUI projects. What do you mean by a template approach? Most of my programming experience is command line based with C++ and Python.

toadzky
Junior Poster in Training
96 posts since Mar 2007
Reputation Points: 10
Solved Threads: 0
 

For instance, if you had to write a program that asks for two values from the user to solve a mathematical equation, you could adopt this Tkinter program as a basic template. Simply change some of the text and the equation and you are done ...

# tk_template_2entry_3label_1button1.py
# a Tkinter template to solve a mathematical equation
# requesting two values from the user
# uses 2 Entry widgets, 3 Label widgets and 1 Button widget

try:
    # Python2
    import Tkinter as tk
except ImportError:
    # Python3
    import tkinter as tk

def calculate():
    """ calculate the resistance of two resistors in parallel """
    try:
        r1 = float(enter1.get())
        r2 = float(enter2.get())
        if r1 + r2 > 0:
            rp = (r1 * r2) / (r1 + r2)
            label3.config(text='Parallel resistance = ' + str(rp))
        else:
            label3.config(text='division by zero error')
    except ValueError:
        label3.config(text='Enter numeric values for r1 and r2')

def setfocus2(event):
    enter2.focus_set()

        
# create root window
root = tk.Tk()

# create all the components
label1 = tk.Label(root, text='Enter value of resistor1:', width=28)
enter1 = tk.Entry(root, bg='yellow')
label2 = tk.Label(root, text='Enter value of resistor2:')
enter2 = tk.Entry(root, bg='yellow')
btn1 = tk.Button(root, text='Calculate', command=calculate)
label3 = tk.Label(root, text='', bg='green')
# pack the root window in that order
label1.pack(side='top', fill='x')
enter1.pack(side='top', fill='x')
label2.pack(side='top', fill='x')
enter2.pack(side='top', fill='x')
btn1.pack(side='top')
label3.pack(side='top', fill='x')

# cursor in enter1
enter1.focus()
# return key in enter1 sets focus to enter2
enter1.bind("<Return>", func=setfocus2)

# start event loop and program
root.mainloop()
vegaseat
DaniWeb's Hypocrite
Moderator
5,989 posts since Oct 2004
Reputation Points: 1,345
Solved Threads: 1,417
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: