Professional Documents
Culture Documents
import tkinter as tk
window = tk.Tk()
def fungsi1():
print(789/456)
def fungsi2():
print(200*200)
button.pack()
button1.pack()
window.mainloop()
import tkinter as tk
window = tk.Tk()
def fungsi1():
print(789/456)
def fungsi2():
print(200*200)
button.pack()
button1.pack()
window.mainloop()
import tkinter as tk
def on_button_click(event):
text=event.widget.cget("text")
if text == "=":
try:
result = str(eval(entry.get()))
entry.delete(0, tk.END)
entry.insert(tk.END, result)
except Exception as e:
entry.delete(0, tk.END)
entry.insert(tk.END, "KokError")
button_frame = tk.Frame(root)
button_frame.pack()
buttons = [
"7", "8", "9", "/",
"4", "5", "6", "*",
"1", "2", "3", "-",
"C", "0", "=", "+"
]
row, col = 1, 0
for button_text in buttons:
button = tk.Button(button_frame, text=button_text, font=("Arial", 24), width=3, height=1)
button.grid(row=row, column=col, padx=5, pady=5, ipadx=2, ipady=2)
col +=1
if col > 3:
col = 0
row += 1
button.bind("<Button-1>", on_button_click)
root.mainloop()
import tkinter as tk
def on_button_click(event):
text=event.widget.cget("text")
if text == "=":
try:
result = str(eval(entry.get()))
entry.delete(0, tk.END)
entry.insert(tk.END, result)
except Exception as e:
entry.delete(0, tk.END)
entry.insert(tk.END, "Error")
button_frame = tk.Frame(root)
button_frame.pack()
buttons = [
"7", "8", "9", "/",
"4", "5", "6", "*",
"1", "2", "3", "-",
"C", "0", "=", "+"
]
row, col = 1, 0
for button_text in buttons:
button = tk.Button(button_frame, text=button_text, font=("Arial", 24), width=3, height=1)
button.grid(row=row, column=col, padx=5, pady=5, ipadx=2, ipady=2)
col +=1
if col > 3:
col = 0
row += 1
button.bind("<Button-1>", on_button_click)
root.mainloop()
if text == "=":
try:
result = str(eval(entry.get()))
entry.delete(0, tk.END)
entry.insert(tk.END, result)
except Exception as e:
entry.delete(0, tk.END)
entry.insert(tk.END, "Error")
Apa yang terjadijika “except” di hapus dan menyisakan try sajatanpa except
A Terjadi error dan program tidakberjalan
B Tidakterjadiapaapa
C Hasil dapat di keluarkandenganbaik
D Muncultulisan Error pada kalkulator
E Program error jikamemasukanpembagian yang salah
6 Perhatikanpilihandibawah:
A) a = “hallo”
B) b = 23
C) c = 2.5
D) d = ‘dunia’
E) e = 700
Dari point-point diatas, variable manakah yang memilikitipe data Integer?
A A dan B
B B dan C
C C dan D
D B dan E
E A dan E
7 Perhatikanpilihandibawah:
A) a = “hallo”
B) b = 23
C) c = 2.5
D) d = 8.5
E) e = 700
A) a = “hallo”
B) b = 23
C) c = 2.5
D) d = True
E) e = False
nilai = 3+6-1*7/2
print(nilai)
a = 33
b = 38
if b > a:
print("if 1 dijalankan")
if a != b:
print("if 2 dijalankan")
A Senin
B Selasa
C Rabu
D Kamis
E Jumat
23 terdapatsebuah program dan statement sepertidibawah:
if text == "=":
try:
result = str(eval(entry.get()))
entry.delete(0, tk.END)
entry.insert(tk.END, result)
except Exception as e:
entry.delete(0, tk.END)
entry.insert(tk.END, "Error")
a = 200
b = 33
if b > a:
print("b lebihbesardari a")
elif a == b:
print("a dan b bernilaisama")
else:
print("a lebihbesardari b")
Benaratau Salah. Jikakondisi if telahterpenuhi, makajikaelif dan else kondisinyaterpenuhi juga maka
output yang dihasilkanadalahketiga print akan di munculkan.
A Benar
B Salah
C
D
E
25 Terdapat Program sebagaiberikut:
a = 33
b = 38
if b > a:
print("if 1 dijalankan")
if a != b:
print("if 2 dijalankan")
Benaratau Salah. Karena keduakondisi if diatasterpenuhimaka output print
akandimunculkansemua.
A Salah
B Benar
C
D
E
26 Pada program Kalkulatorterdapat program seperti di bawah.
buttons = [
"7", "8", "9", "/",
"4", "5", "6", "*",
"1", "2", "3", "-",
"C", "0", "=", "+"
]
row, col = 1, 0
C
D
import tkinter as tk
window = tk.Tk()
window.title("JudulAplikasi")
window.mainloop()
A Salah
B Benar
C
D
E
31 Program manakah yang berfungsiuntukmembuat Text Label dan menampilkannya ?
a) button1 = tk.Button(text="klikdong",height=2,width=10,bg="yellow",command=klik)
button1.pack()
b) button2 = tk.Button(text="mulai",height=2,width=10,bg="yellow",command=klik2)
button2.pack()
A Variabel
B Fungsi
C Integer
D Library
E Float
23 Diberikan program sebagaiberikut:
buttons = [
"7", "8", "9", "/",
"4", "5", "6", "*",
"1", "2", "3", "-",
"C", "0", "=", "+"
]
print(buttons[4])
buttons = [
"7", "8", "9", "/",
"4", "5", "6", "*",
"1", "2", "3", "-",
"C", "0", "=", "+"
]
print(buttons[9])
buttons = [
"7", "8", "9", "/",
"4", "5", "6", "*",
"1", "2", "3", "-",
"C", "0", "=", "+"
]
print(buttons)