Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

HOME ASSIGNMENTS

AI/PYTHON_WARMUP_SESSION_3
HOME ASSIGNMENT 1

Source code:
IMPORT TKINTER AS TK
ROOT = TK.TK()
CANVAS1 = TK.CANVAS(ROOT, WIDTH=700, HEIGHT=500)
CANVAS1.PACK()

LABEL1 = TK.LABEL(ROOT, TEXT='OUTLOOK: ')


CANVAS1.CREATE_WINDOW(100, 100, WINDOW=LABEL1)
LABEL2 = TK.LABEL(ROOT, TEXT='TEMPERATURE: ')
CANVAS1.CREATE_WINDOW(100, 120, WINDOW=LABEL2)
LABEL3 = TK.LABEL(ROOT, TEXT='HUMIDITY: ')
CANVAS1.CREATE_WINDOW(100, 140, WINDOW=LABEL3)
LABEL4 = TK.LABEL(ROOT, TEXT='WINDY: ')
CANVAS1.CREATE_WINDOW(100, 160, WINDOW=LABEL4)

ENTRY1 = TK.ENTRY(ROOT)
CANVAS1.CREATE_WINDOW(270, 100, WINDOW=ENTRY1)
ENTRY2 = TK.ENTRY(ROOT)
CANVAS1.CREATE_WINDOW(270, 120, WINDOW=ENTRY2)
ENTRY3 = TK.ENTRY(ROOT)
CANVAS1.CREATE_WINDOW(270, 140, WINDOW=ENTRY3)
ENTRY4 = TK.ENTRY(ROOT)
CANVAS1.CREATE_WINDOW(270, 160, WINDOW=ENTRY4)

DEF VALUES():
OUTLOOK = FLOAT(ENTRY1.GET())
TEMP = FLOAT(ENTRY2.GET())
HUMIDITY = FLOAT(ENTRY3.GET())
WINDY = FLOAT(ENTRY4.GET())

PREDICTION_RESULT = DTREE.PREDICT([[OUTLOOK, TEMP, HUMIDITY, WINDY]])


RESULT_TEXT = 'PREDICT TO PLAY TABLE TENNIS OR NOT: ' + STR(PREDICTION_RESULT)
LABEL_PREDICTION = TK.LABEL(ROOT, TEXT=RESULT_TEXT, BG='ORANGE')
CANVAS1.CREATE_WINDOW(200, 230, WINDOW=LABEL_PREDICTION)

BUTTON1 = TK.BUTTON(ROOT, TEXT='PREDICT TO PLAY TABLE TENNIS OR NOT:', COMMAND=VALUES, BG='ORANGE')


CANVAS1.CREATE_WINDOW(200, 190, WINDOW=BUTTON1)

ROOT.MAINLOOP()
Output
HOME ASSIGNMENT 2
Q1 What is the purpose of using tkinter library ?
It is used by the coders to add GUI widgets to the front end of the application

Q2 Write the syntax how to make a window screen in GUI.


root = tk.Tk()
window = tk.Canvas(root, width, height)
window.pack()

Q3 Write the syntax how to add labels in GUI.


label1 = tk.Label(root, text=' ')
canvas1.create_window(x, y, window=label1)

Q4Write the syntax how to add buttons in GUI


button1 = tk.Button(root, text='text', command, bg='color')
canvas1.create_window(x, y, window=button1)
Q5 Write the syntax how to add entry box in GUI.
entry1 = tk.Entry(root)
canvas1.create_window(x, y, window=entry1)

Q6Made a GUI window of background color as pink by following hint


window = tk.Tk()
window.configure(bg='pink')
window.mainloop()

You might also like