jupyter notebook questions. solve in python. thank you
Posted: Mon May 02, 2022 12:40 pm
jupyter notebook questions. solve in python. thank you
Task 1: Adder with Tkinter (30%) Please create a simple adder using Tkinter. • The GUI should look like the image below. Your widgets could be at arbitrary width and height. But their relatively position should be the same as below. • The user should be able to input two numbers via two text entries. You can safely assume users will input valid integer number . When the user click the button with equal sign, the result should be shown at the right-most label. Label tk #16 3 button text entry import tkinter as tk def on_calc(event): #CALCULATE THE ANSWER ans = lab2["text"] = str(ans) window tk.Tk) ent1 = ... ent1.pack(side=tk. LEFT) =... label = label.pack(side=tk. LEFT) ent2 = ent2.pack(side=tk. LEFT) bnt1 = ... bnt1.pack(side=tk. LEFT) lab2 = ... lab2.pack(side=tk. LEFT) # .pack method adds the Label to the window. window.mainloop
Task 2: Buttons (30%) Use Tkinter to create the GUI below. The UI contains one label and two buttons. When click "add 1", the number should increase by 1. When click the "minus 1" button, the number on the label should decrease by 1. The dimension of all three widgets should be width = 10, height = 5 tk #A minus 1 add 1 0 import tkinter as tk ans = def on_add(event): def on_minus (event): bnt1 tk.Button text = 'minus 1', width = 10, height = 5 > bnt1.pack(side=tk. LEFT) bnt2 = tk.Button text = 'add 1', width = 10, height = 5 > bnt2.pack(side=tk. LEFT) lab = tk. Label text = width 10, height = 5 ) lab.pack(side=tk. LEFT) # INSERT YOUR CODE BELOW # Bind the on_button_click to the button # 2 Lines window.mainloop()
Task 1: Adder with Tkinter (30%) Please create a simple adder using Tkinter. • The GUI should look like the image below. Your widgets could be at arbitrary width and height. But their relatively position should be the same as below. • The user should be able to input two numbers via two text entries. You can safely assume users will input valid integer number . When the user click the button with equal sign, the result should be shown at the right-most label. Label tk #16 3 button text entry import tkinter as tk def on_calc(event): #CALCULATE THE ANSWER ans = lab2["text"] = str(ans) window tk.Tk) ent1 = ... ent1.pack(side=tk. LEFT) =... label = label.pack(side=tk. LEFT) ent2 = ent2.pack(side=tk. LEFT) bnt1 = ... bnt1.pack(side=tk. LEFT) lab2 = ... lab2.pack(side=tk. LEFT) # .pack method adds the Label to the window. window.mainloop
Task 2: Buttons (30%) Use Tkinter to create the GUI below. The UI contains one label and two buttons. When click "add 1", the number should increase by 1. When click the "minus 1" button, the number on the label should decrease by 1. The dimension of all three widgets should be width = 10, height = 5 tk #A minus 1 add 1 0 import tkinter as tk ans = def on_add(event): def on_minus (event): bnt1 tk.Button text = 'minus 1', width = 10, height = 5 > bnt1.pack(side=tk. LEFT) bnt2 = tk.Button text = 'add 1', width = 10, height = 5 > bnt2.pack(side=tk. LEFT) lab = tk. Label text = width 10, height = 5 ) lab.pack(side=tk. LEFT) # INSERT YOUR CODE BELOW # Bind the on_button_click to the button # 2 Lines window.mainloop()