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

Using Tkinter for GUI, A Python program that will allow the user to perform (i) generate...
Using Tkinter for GUI, A Python program that will allow the user to perform (i) generate RSA keys, (ii) encrypt a given message and (iii) decrypt the message without using any cryptographic library. Your program will generate the values of p unless the user provides them manually. Then the program will generate the keys (private and public). Then the program will allow the user to enter his/her message to be encrypted. Finally, the program will perform the decryption operation as...
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...
I did the complete programming in python , just want to use tkinter for GUI. please...
I did the complete programming in python , just want to use tkinter for GUI. please look at the 2nd part . i did some part of this program using tkinter but could not finis it. Thank you. import random image = 'w' # modified functions which accepts two numbers each and returns the respective # output def add(a, b): return a + b def subtract(a, b): return a - b def multiply(a, b): return a * b def kidCalc():...
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        ...
In Python, create a program with 2 classes that do the following. HashCreate class, this class...
In Python, create a program with 2 classes that do the following. HashCreate class, this class will accept a directory and hash each file in the directory and store the results in a dictionary. The dictionary will contain the hash value and file name. HashVerify, the second class will accept the dictionary as input and save that in an instance attribute. This class must also contain a method for lookups that require a file path as input. The lookup method...
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 =...
Using Python, create a program that will act as a number convertor. This program will convert...
Using Python, create a program that will act as a number convertor. This program will convert an input decimal integer into binary and hexadecimal formats. a) Define a main function named numberconvertor(). Inside the main function, write all the logic of your code. [5% marks] b) Looping indefinitely (Hint: use infinite while loop), the program should give the user the 3 options given below and allow the user to select one among them. [15% marks] 1. converting a decimal number...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT