Question

In: Computer Science

In python using tkinter, I want to create a program. The program can have various classes...

In python using tkinter, I want to create a program. The program can have various classes and methods but I want it to have circles, triangles, and squares. Each shape movies in a certain way, like circles can move linearly, triangles can be affected by gravity, and squares can only go up and down. If the shapes get too close to one another then they disappear and a new shape appears somewhere else. I want this program to run continuously.

Solutions

Expert Solution


# Imports each and every method and class
# of module tkinter and tkinter.ttk

from tkinter import * from tkinter.ttk import * class Shape:

def __init__(self, master = None):

self.master = master

  

# Calls create method of class Shape

self.create()

  

def create(self):

  

# Creates a object of class canvas

# with the help of this we can create different shapes

self.canvas = Canvas(self.master)

  

# Creates a circle of diameter 80

self.canvas.create_oval(10, 10, 80, 80,  

outline = "black", fill = "white",

width = 2)

  

# Creates an ellipse with horizontal diameter

# of 210 and vertical diameter of 80

self.canvas.create_oval(110, 10, 210, 80,

outline = "red", fill = "green",

width = 2)

  

# Creates a rectangle of 50x60 (heightxwidth)

self.canvas.create_rectangle(230, 10, 290, 60,

outline = "black", fill = "blue",

width = 2)

  

# Creates an arc of 210 deg

self.canvas.create_arc(30, 200, 90, 100, start = 0,

extent = 210, outline = "green",

fill = "red", width = 2)

  

points = [150, 100, 200, 120, 240, 180,

210, 200, 150, 150, 100, 200]

  

# Creates a polygon

self.canvas.create_polygon(points, outline = "blue",

fill = "orange", width = 2)

# Pack the canvas to the main window and make it expandable

self.canvas.pack(fill = BOTH, expand = 1)

  

if __name__ == "__main__":

  

# object of class Tk, resposible for creating

# a tkinter toplevel window

master = Tk()

shape = Shape(master)

  

# Sets the title to Shapes

master.title("Shapes")

  

# Sets the geometry and position

# of window on the screen

master.geometry("330x220 + 300 + 300")

  

# Infnite loop breaks only by interrupt


Related Solutions

can you please create the code program in PYTHON for me. i want to create array...
can you please create the code program in PYTHON for me. i want to create array matrix Nx1 (N is multiple of 4 and start from 16), and matrix has the value of elements like this: if N = 16, matrix is [ 4 4 4 4 -4 -4 -4 -4 4 4 4 4 -4 -4 -4 -4] if N = 64, matrix is [8 8 8 8 8 8 8 8 -8 -8 -8 -8 -8 -8 -8...
Python Using tkinter, create a GUI interface which accepts input of a GPA. If the GPA...
Python Using tkinter, create a GUI interface which accepts input of a GPA. If the GPA is >= 3.5, display 'Dean’s List' If the GPA is < 2.0, display 'Probation’ If the GPA is < 3.5 and >= 2.0, display 'Regular Standing' Run one test case for each case above and save the output.
In python I have a linked list. I want to create one function that takes in...
In python I have a linked list. I want to create one function that takes in one parameter, head. In the function, cur = head and next_cur = head.next. I want to return head and next_cur, except at the end of the function they will return alternating values from head. For example, if the these are the values in the linked list: 2, 3, 5, 7, 11 after the function head should return: 2, 5, 11 and next_cur should return:...
In python I want to create a function that takes in a linked list. Using recursion...
In python I want to create a function that takes in a linked list. Using recursion only, I want to check if the linked list is sorted. How do i do this?
I am having a trouble with a python program. I am to create a program that...
I am having a trouble with a python program. I am to create a program that calculates the estimated hours and mintutes. Here is my code. #!/usr/bin/env python3 #Arrival Date/Time Estimator # # from datetime import datetime import locale mph = 0 miles = 0 def get_departure_time():     while True:         date_str = input("Estimated time of departure (HH:MM AM/PM): ")         try:             depart_time = datetime.strptime(date_str, "%H:%M %p")         except ValueError:             print("Invalid date format. Try again.")             continue        ...
I want to create an image compression program with matlab use PCA. I have the code...
I want to create an image compression program with matlab use PCA. I have the code listed below. But this code is fail, the image is colorless, but still gray. Can you help me to fix my code. clc clear all picture = im2double(imread('picture1.jpg')); Red = picture(:,:,1); premean = mean(Red(:)); premax = max(Red(:)); premin = min(Red(:)); x = size(Red,1); y = size(Red,2); Z = ones(x,y)*premean; A = (Red - Z)*(1/premax - premin); B = cov(A); [veceig,eig,C] = pcacov(B); NewRed =...
Python Create a tkinter GUI application that has two buttons on it. The first button should...
Python Create a tkinter GUI application that has two buttons on it. The first button should have in red text the word "Red" on it and the second button should have in blue text the word "Blue" on it. When the red button is clicked you should change the background color of the application window to red and when the blue button is pressed you should change the background color of the application window to blue. You should place your...
I NEED TO CREATE A GUI INTERFACE USING TKINTER CONTAINING : Colors, Image, Button, Title bar,...
I NEED TO CREATE A GUI INTERFACE USING TKINTER CONTAINING : Colors, Image, Button, Title bar, and a Menu bar FOR THE QUESTION BELOW: PLEASE HELP PROGRAMMING LANGUAGE IS PYTHON Write a simple quiz game that has a list of ten questions and a list of answers to those questions. The game should give the player four randomly selected questions to answer. It should ask the questions one-by-one, and tell the player whether they got the question right or wrong....
In python i want to create a function. The function will take in two linked lists...
In python i want to create a function. The function will take in two linked lists as the parameters. If one is shorter than the other then the shorter will be the length. I want to take the values from both linked lists and turn them into tuples. I then want these tuples to be put into a new linked list. I want to return that linked list. I want to do this using recursion and no helper functions or...
USING PYTHON Write a program to create a number list. It will call a function to...
USING PYTHON Write a program to create a number list. It will call a function to calculate the average values in the list. Define main ():                        Declare variables and initialize them                        Create a list containing numbers (int/float)                        Call get_avg function that will return the calculated average values in the list.                                       Use a for loop to loop through the values in the list and calculate avg                        End main()
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT