Create a program that shows an image with Toggle Image

Assignment Help Python Programming
Reference no: EM132367443

Programming Principles Assignment - GUI Programming

Task 1 - Main Window Settings

We looked into setting options for widgets in the lecture to define things such as size, colour, position, padding and so on. What we didn't really examine was the main window of the program.

The "Tk" class creates this, and it is the first line in the constructor when creating a GUI class:

import tkinter

class ProgramGUI: # define a ProgramGUI class

def __init__(self):

self.main = tkinter.Tk() # create the main window

tkinter.mainloop()

gui = ProgramGUI() # create a ProgramGUI object

While the "Tk" class creates the main window of an application, additional windows can be created using the "TopLevel" widget/class. The main window is a special type of "TopLevel", and hence most of what you can do to configure a "TopLevel" can be applied to the main window.

So how do you do things such as setting the window title and size? That's for you to find out! Do some research and see if you can figure out (and test) how to do the following:

  • Set the main window title. (Hint: See the lecture examples)
  • Set the main window size. (Hint: Use the "geometry()" method)
  • Prevent the main window from being resized/maximised. (Hint: Use the "resizable()" method)
  • Change the icon in the top left of the main window. (Hint: Use the "iconbitmap()" method)

So far, all of these settings involve calling a method on our main window object (self.main). Hopefully your research informed you of the parameters you need to pass to the methods.

Some other aspects of the main window can be configured by using its "configure()" method, which works similar to setting options for widgets. Find out how to do the following:

  • Set the background colour of the main window.
  • Set the cursor to be used when the mouse is over the main window.

There's another way of configuring the main window which isn't properly implemented yet. It involves using the main window's "attributes()" method. Since it isn't properly implemented the settings must be set differently, e.g. instead of "attributes(alpha=0.5)" you must do "attributes('-alpha', 0.5)". See the list of settings here or here and try to:

  • Set the alpha of the main window to make it semi-transparent.
  • Set the main window to be always on top of other windows.
  • Set the main window to be full-screen. (Press Alt+F4 to close it)

Task 2 - Working With Images

So far, none of our GUI programs have included images. Before we display an image in our program, find a ".gif" or ".png" image file and copy it into the same directory as your code. While it is possible to show images in other formats, more work is needed.

To display the image in your program, you first need to create a "PhotoImage" object (part of the "tkinter" module) and set the image's filename as the "file" parameter in the constructor:

self.logo = tkinter.PhotoImage(file='logo1.png')

You can then refer to this object in other widgets that can show or otherwise use images. The simplest is a "Label", which we have only used to display text until now. Instead of specifying the "text" setting when you create a label, specify the "image" setting and reference the object.

Using this knowledge and what we have covered in the lecture, create a program that shows an image and a Button with "Toggle Image" written on it. Every click of the button toggles the image between two different image files. Here are some hints to help you:

  • Change the "file" setting of the "PhotoImage" object whenever the button is clicked. This will cause the "Label" object to show the new image.
  • To read the value of a widget setting, use the "cget()" method on the widget object. This can be used to determine which file the "PhotoImage" object is displaying.
  • Use the "configure()" method on the "PhotoImage" object to change the file setting.

Task 3 - Radio Buttons and Check Buttons

Radio buttons and checkboxes are quite commonly seen in a GUI. Radio buttons allow the user to select one option from a group, while checkboxes allow the user to select as many as they want. The "tkinter" module implements these via the "Radiobutton" and "Checkbutton" classes.

Section 13.8 of the textbook covers the usage of radio buttons and checkboxes, but you can also find tutorials and references online. Some of the key things to keep in mind regarding them are:

The "variable" setting links a "Radiobutton" or a "Checkbutton" to a Tk variable.

  • Commonly this is an "IntVar", but it can be a "StringVar" and so on. Every "Radiobutton" in a group must link to the same variable, while each "Checkbutton" should link to a different variable.
  • You can "set()" the variable's value to match the value of a "Radiobutton" or "Checkbutton" in order to specify a default radio button selection or checkboxes that start out already checked.

The "value" setting of a "Radiobutton" defines what the variable is set to when you select that option. Every button in the group should have a different "value".

The "offvalue" and "onvalue" settings of a "Checkbutton" define what the variable is set to when the box is unchecked or checked. The "onvalue" is usually the relevant one.

To determine the value of a "Radiobutton" or if a "Checkbutton" is checked, read the value of the variable linked to it using the variable's "get()" method.

Once you feel you have a grasp of how to use "Radiobutton" and "Checkbutton", try to implement the program depicted and described below:

This program uses two labels, three radio buttons, three checkboxes and a button to create a GUI for specifying the details of a toasted sandwich. Some frames are also used for the layout. When the Submit Order button is pressed, one of two windows can appear.

The code in the event handler for the button is not particularly complicated, but be sure to spend some time thinking about it and planning it before you jump in and start trying to code it!

Note - For more details see attached file.

Attachment:- Assignment File - GUI Programming.rar

Reference no: EM132367443

Questions Cloud

Create the empty usernames dictionary before the loop : Create the empty "usernames" dictionary before the loop, and add usernames to it at the end of the loop body (once you've ensured that they are long enough)
Appropriate hypotheses and calculate the test statistic : You like to see whether the mean monthly maintenance cost has increased. Set the appropriate hypotheses and calculate the test statistic
Construct a confidence interval : The results of a pre election poll suggested that 50% of the people surveyed (n=500) indicated that they would vote for Hillary Clinton in the soon
Confidence interval tell about the population : What does the confidence interval tell about the population of all college students in the? state?
Create a program that shows an image with Toggle Image : Using this knowledge and what we have covered in the lecture, create a program that shows an image and a Button with "Toggle Image" written on it
Estimate just the value that maximizes the mle function : If the parameter is not known but it has been narrowed down to 3 possible values, is the maximum likelihood estimate just the value
How many different ways can a senior project manager : How many different ways can a senior project manager and an associate project manager be selected for an analytics project if there are seven data scientists av
What percent of the entrants had distances : What percent of the entrants had distances between 150 and 160 feet? Round your answer to two decimal places.
Determine the expected output of your tests yourself : CSP1150/CSP5110 Programming Principles Assignment - Testing and Quality Assurance, Edith Cowan University, Australia. Determine expected output of your tests

Reviews

Write a Review

Python Programming Questions & Answers

  Write a python program to implement the diff command

Without using the system() function to call any bash commands, write a python program that will implement a simple version of the diff command.

  Write a program for checking a circle

Write a program for checking a circle program must either print "is a circle: YES" or "is a circle: NO", appropriately.

  Prepare a python program

Prepare a Python program which evaluates how many stuck numbers there are in a range of integers. The range will be input as two command-line arguments.

  Python atm program to enter account number

Write a simple Python ATM program. Ask user to enter their account number, and print their initail balance. (Just make one up). Ask them if they wish to make deposit or withdrawal.

  Python function to calculate two roots

Write a Python function main() to calculate two roots. You must input a,b and c from keyboard, and then print two roots. Suppose the discriminant D= b2-4ac is positive.

  Design program that asks user to enter amount in python

IN Python Design a program that asks the user to enter the amount that he or she has budget in a month. A loop should then prompt the user to enter his or her expenses for the month.

  Write python program which imports three dictionaries

Write a Python program called hours.py which imports three dictionaries, and uses the data in them to calculate how many hours each person has spent in the lab.

  Write python program to create factors of numbers

Write down a python program which takes two numbers and creates the factors of both numbers and displays the greatest common factor.

  Email spam filter

Analyze the emails and predict whether the mail is a spam or not a spam - Create a training file and copy the text of several mails and spams in to it And create a test set identical to the training set but with different examples.

  Improve the readability and structural design of the code

Improve the readability and structural design of the code by improving the function names, variables, and loops, as well as whitespace. Move functions close to related functions or blocks of code related to your organised code.

  Create a simple and responsive gui

Please use primarily PHP or Python to solve the exercise and create a simple and responsive GUI, using HTML, CSS and JavaScript.Do not use a database.

  The program is to print the time

The program is to print the time in seconds that the iterative version takes, the time in seconds that the recursive version takes, and the difference between the times.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd