Gooey Pie Logo

GooeyPie

Updates About

Getting started with GooeyPie

GooeyPie is an intuitive and beginner-friendly Python GUI library.

Watch the 5-minute Getting Started video

Installing GooeyPie

Open a command prompt or terminal window and use pip to install GooeyPie:

  Windows

pip install gooeypie

  Mac

pip3 install gooeypie

Is pip blocked at your school or workplace? check out your other options.

Hello GooeyPie

After installing GooeyPie, create a new .py file and import the gooeypie library:

import gooeypie as gp

Importing the library as gp just means you'll be able to use the gp prefix in the rest of your code for less typing!

Next, we'll create our application:

app = gp.GooeyPieApp('Hello!')

We can call the application variable whatever we want, but app makes sense.

Let's define the size of our app. Normally we let the widgets in the app define the size for us, but we'll give ourselves a bit of extra room here:

app.width = 250

And now we can run the application by adding the following:

app.run()

You should get the following window, depending on your operating system:

A blank window, but it's a start

It's not much, but it's got a title, an icon, and standard window controls for minimising, maximising and closing the window. Closing the window terminates the program.

Let's put stuff on it! Before the call to app.run(), add the following:

hello_btn = gp.Button(app, 'Say Hello', None)
hello_lbl = gp.Label(app, '')

What we've done here is create two widgets (a label and a button), and associate those with our app.

These widgets are the building blocks of your interface. However, you'll notice that if you run the code, we still see an empty window. That's because while we've created the widgets, we haven't added them to our application yet.

All widgets are added to a window (or another container) in a grid. And so the first thing we have to do is define the dimensions of the grid. Add this line:

app.set_grid(2, 1)

This line tells us our app has 2 rows and 1 column. And now we can add the button and the label we previously created into this grid using the same row and column numbering:

app.add(hello_btn, 1, 1, align='center')
app.add(hello_lbl, 2, 1, align='center')

We've added the button into the first row (and first column), and the label into the second row.

Run the application and we get our button! There's also a label there but we can't see it because the text of the label is set to the empty string.

But our button does nothing! Let's fix that. The first thing we need to do is write a function that will be called when the button is pressed. Add this function after the import statement:

def say_hello(event):
    hello_lbl.text = 'Hello Gooey Pie!'

The function is called say_hello and takes a single argument. All GooeyPie event functions are passed an event object that gives the function access to information like which widget and event triggered the function, any keys pressed and where the mouse was at the time.

The function say_hello just changes the text of the label from the empty string to a nice welcoming message by assigning the message to the .text property of our label object.

All that's left to do now is change the None we wrote when we created the button to the name of our event function (without the brackets).

Change the code to:

hello_btn = gp.Button(app, 'Say Hello', say_hello)

And there it is - your first working GooeyPie app!

 

The complete code


    
    

Hopefully that gives you a taste of what GooeyPie can do and how it works. There's lots more in the widgets pages with more events and layout examples.

🡹