Tkinter is packed with options

The pack() method lets you position the button in the application window. If you provide a value for the side parameter to pack (), you can control where in the window the button appears. Here are the legal values for side:

Position the button on the left side of the window.

Position the button on the right side of the window.

Position the button at the top of the window.

Position the button at the bottom of the window.

It is also possible to add some padding around buttons (to make them look nicer in your window):

The value of "side" ┬┐oirtvols where -the bu-ttoin is packed.

Position the button with 10 pixels padding on all four sides.

Based on what you now know about tkinter windows and buttons, write the code to display the GUI that you need for the TVN program:

gooey display

iharpen your pencil ^ , Solution

Based on what you now know about tkinter windows and buttons, you were to write the code to display the GUI that you need for the TVN program:

from tkinter import *

Create the window as in the earlier example, app = Tk()

tr&t^japp.^tleCTVN. Game Show")

values- app.geometry('300xl00+200+l00')

Create a button for

bl = ButWapp, text = "Correct'", width = 10)

bl.pack(side = 'left', padx = 10, pady = 10) b2 = ButWapp, text = "Wrong'", width = 10)

Pack one button on the left, the other on the right, and give them some padding.

for the 'Wong" event-

AW

Tost DRIVQ

There's a convention in the Python

Let's take your first GUI program for a test drive. With your tkinter code entered into IDLE, save it as tvn. pyw and press F5 to see how it looks:

Your code in IDLE

programs with a "pyw" extension, as opposed to the usual "py"- This helps your operating system run your tkinter programs properly, especially on Windows.

There's your GUI window..

..and there are your two buttons.

There's your GUI window..

..and there are your two buttons.

That's one nice, professional-looking GUI! What do the people at TVN think?

beauty without brains

Was this article helpful?

0 0

Post a comment