How to create canvas and frame in GUI using python?

Description

To create a canvas and frame using python3.

Canvas:

  It is used to draw pictures and other
complex layout like graphics, text and
widgets.

Frame:

   It acts as a container to hold the widgets.
It is used for grouping and organizing
the widgets.

Source code(Canvas):

 #import tkinter

from tkinter import *

#create root window

top = Tk()

#define canvas variable

w = Canvas(top, bg = “green”,

height = 150, width = 300)

#define coordinates to create arc

coord = 10, 50, 240, 210

oval = w.create_oval(coord,fill = “white”)

line = w.create_line

(10,10,200,200,fill = ‘black’)

w.pack()

top.mainloop()

 

 

Source code(Frame):

 #import tkinter

import tkinter as tk

#create root window

top = tk.Tk()

#create GUI frame

frame = Frame(top)

frame.pack()

bottomframe = Frame(top)

bottomframe.pack

( side = BOTTOM )

#buttons

Enggbutton = Button

(frame, text = ‘Engineering’, fg =’red’)

Enggbutton.pack( side = LEFT)

Artsbutton = Button

(frame, text = ‘Arts’, fg=’white’)

Artsbutton.pack( side = LEFT )

Medicalbutton = Button

(frame, text =’Medical’,fg =’green’)

Medicalbutton.pack( side = LEFT )

Diplomabutton = Button

(frame, text =’Diploma’,fg =’black’)

Diplomabutton.pack( side = BOTTOM)

#trigger mainloop

top.mainloop()

Leave Comment

Your email address will not be published. Required fields are marked *

clear formSubmit