Question

PYTHON make 2 radio buttons in a window; one says matinee one says evening. When one...

PYTHON make 2 radio buttons in a window; one says matinee one says evening. When one of them is clicked it leads to a window that has a picture. Please avoid using PIP if at all possible

0 0
Add a comment Improve this question Transcribed image text
Answer #1

HERE IS THE CODE FOR CREATING TWO RADIO BUTTONS AND OPENING NEW WINDOWS WITH IMAGES BY CLICKING THEM USING PYTHON TKINTER.

from tkinter import *
import tkinter as tk

root = Tk()
root.geometry('300x300')
v = tk.IntVar()
def new_window1(): # new window definition
newwin = Toplevel(root)

newwin.title("Matinee Show")

    photo = PhotoImage(file="Desktop\matinee.gif")
display = Label(newwin, image = photo)
display.pack()
newwin.mainloop()
  
def new_window2(): # new window definition
newwin = Toplevel(root)

newwin.title("Evening Show")
photo = PhotoImage(file="Desktop\matinee.gif")
display = Label(newwin, image = photo)
display.pack()
newwin.mainloop()

radioButton1 = Radiobutton(root,variable=v , value = 0 , text="Matinee", command=new_window1)
radioButton2 = Radiobutton(root,variable=v , value = 1 , text="Evening", command=new_window2)
radioButton1.pack()
radioButton2.pack()
root.mainloop()

Please take a look of the screenshot below.

NOTE : The code is run in Thonny (PYTHON EDITOR) under the version of the PYTHON 3.7.4

PLEASE FOLLOW THE "INDENTATIONS" OF THE CODE AND "INSTALL TKINTER" BEFORE RUNNING THE ABOVE CODE

IF YOU USE PYCHARM ALSO MAKE SURE YOU HAVE TKINTER INSTALLED

OUTPUT

HOW IT WORKS?

1.

from tkinter import *
import tkinter as tk

root = Tk()
root.geometry('300x300')
v = tk.IntVar()

THIS CODE IMPORTS TKINTER AND CREATES A WINDOW WITH 300x300 DIMENSIONS AND CREATES A VARIABLE V TO STORE VALUES OF RADIO BUTONS.


def new_window1(): # new window definition
newwin = Toplevel(root)

newwin.title("Matinee Show")

    photo = PhotoImage(file="Desktop\matinee.gif")
display = Label(newwin, image = photo)
display.pack()
newwin.mainloop()
  
def new_window2(): # new window definition
newwin = Toplevel(root)

newwin.title("Evening Show")
photo = PhotoImage(file="Desktop\matinee.gif")
display = Label(newwin, image = photo)
display.pack()
newwin.mainloop()

new_window1 and new_window2 ARE THE FUNCTIONS THAT ARE CALLED WHEN RADIO BUTTONS ARE CLICKED

radioButton1 = Radiobutton(root,variable=v , value = 0 , text="Matinee", command=new_window1)
radioButton2 = Radiobutton(root,variable=v , value = 1 , text="Evening", command=new_window2)
radioButton1.pack()
radioButton2.pack()
root.mainloop()

THIS IS THE CODE TO CREATE RADIO BUTTONS SAYING "matinee" AND "evening".

i HAVEN'T USED THE VARIABLE "V" IN THE CODE YOU CAN SKIP THE VARIABLE IF YOU DON'T WANT IT .

Add a comment
Know the answer?
Add Answer to:
PYTHON make 2 radio buttons in a window; one says matinee one says evening. When one...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • How to use textbox, radio buttons, checkbox, and dropdown list to make up a quiz of...

    How to use textbox, radio buttons, checkbox, and dropdown list to make up a quiz of 20 questions ... How to use textbox, radio buttons, checkbox, and dropdown list to make up a quiz of 20 questions ONLY using JavaScript. No Jquery. When the quiz starts, the questions don't appear all at once, it will display one question at a time with a next button, until the last question with Submit button. Finally, when the quiz is finished, display the...

  • JAVA SOLUTION This lab has four parts: Create a window. Create 5 buttons in that window....

    JAVA SOLUTION This lab has four parts: Create a window. Create 5 buttons in that window. Create an event when a button is pushed. Create an event listener that will respond to the button being pushed event. Task 1 – Create a Window For Java: Please ensure that the following import statements are used: import javafx.application.Application; import javafx.stage.Stage; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.layout.GridPane; import javafx.scene.text.Text; import javafx.event.EventHandler; import javafx.scene.input.MouseEvent; Next, ensure that there is a main method which is...

  • I am trying to make it so that radio buttons when clicked execute a javascript file....

    I am trying to make it so that radio buttons when clicked execute a javascript file. I have to to have the exercises in external files. Here is what I have so far. I am reusing a script that was used to make radio buttons switch CSS files so I think I have to change the set attribute options. HTML <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> </head> <body> <p> 4.2 Output: The first 20 Fibonacci numbers, which are...

  • I need help writing the code for a GUI calculator that uses 4 Radio Buttons (+....

    I need help writing the code for a GUI calculator that uses 4 Radio Buttons (+. -, * , /). Only one button can be selected at a time. I also have to group the buttons for this i am importing the ToggleGroup and using that. The user also need to select one function to begin with or an "Error" message will show if they select the calculate button. I would really like to know what needs to be used...

  • Write a program that simulates a traffic light. When a radio button is selected, the corresponding light is turned on, a...

    Write a program that simulates a traffic light. When a radio button is selected, the corresponding light is turned on, and only one light can be on at a time. No light is on when the program starts. Use Group instead of Pane to combine shapes, and then put the group to the center of a BorderPane will make all shapes staying in center when resizing the window. using NetBeans Java

  • PYTHON PROGRAMMING LANGUAGE (NEEDED ASAP) Using a structured approach to writing the program: This section will...

    PYTHON PROGRAMMING LANGUAGE (NEEDED ASAP) Using a structured approach to writing the program: This section will guide you in starting the program in a methodical way. The program will display a window with GUI widgets that are associated with particular functions: Employee Payroll O X -- - - - - - - - - - - Show Payroll Find Employee by Name Highest Lowest Find Employee by Amount Write Output to Fie Cancel - -------- ------------- Notice that some of...

  • 28. The "Broken Window Fallacy" goes as follows. A baker comes to his shop one morning...

    28. The "Broken Window Fallacy" goes as follows. A baker comes to his shop one morning and discovers someone has thrown a rock through his window. It will cost $300 to fix, and while he is bemoaning this someone says "I know it is hard for you, but socially it is okay. Because the window is broken the glazier will be employed broken? But it does not stop there. The glazier will take the $300 and he will spend it....

  • 1. Please write the following code in Python 3. 2. Please also show all outputs. Create...

    1. Please write the following code in Python 3. 2. Please also show all outputs. Create a dictionary named letter_counts that contains each letter and the number of times it occurs in string1. Challenge: Letters should not be counted separately as upper-case and lower-case. Intead, all of them should be counted as lower-case. string1 = "There is a tide in the affairs of men, Which taken at the flood, leads on to fortune. Omitted, all the voyage of their life...

  • When considering blood transfusion, it is important to make sure the donor and the recipient are...

    When considering blood transfusion, it is important to make sure the donor and the recipient are as compatible as possible to avoid adverse immune response. The patient’s phenotype is A,N, Rh-. a) List all GENOTYPES of potential donors with consideration of all three genes involved b)  The Patient’s wife has phenotype B,M,Rh-, and clearly cannot be a donor. Pick possible genotypes for each parent, which are consistent with eth phenotypes, and will allow producing children that can donate blood to the...

  • Programming question. Using Visual Studio 2019 C# Windows Form Application (.NET Framework) Please include code for...

    Programming question. Using Visual Studio 2019 C# Windows Form Application (.NET Framework) Please include code for program with ALL conditions met. Conditions to be met: Word Problem A person inherits a large amount of money. The person wants to invest it. He also has to withdraw it annually. How many years will it take him/her to spend all of the investment that earns at a 7% annual interest rate? Note that he/she needs to withdraw $40,000.00 a year. Also there...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT