{"id":163,"date":"2025-08-24T14:29:57","date_gmt":"2025-08-24T14:29:57","guid":{"rendered":"https:\/\/learn.rantissi.my.id\/?p=163"},"modified":"2025-08-24T14:29:59","modified_gmt":"2025-08-24T14:29:59","slug":"mini-project-gui-kalkulator-sederhana","status":"publish","type":"post","link":"https:\/\/learn.rantissi.my.id\/index.php\/2025\/08\/24\/mini-project-gui-kalkulator-sederhana\/","title":{"rendered":"Mini Project GUI: Kalkulator Sederhana"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">Struktur Program yang Akan Dibuat:<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Input: 2 angka (<code>Entry<\/code>)<\/li>\n\n\n\n<li>Tombol: <code>+<\/code>, <code>-<\/code>, <code>\u00d7<\/code>, <code>\u00f7<\/code><\/li>\n\n\n\n<li>Label hasil<\/li>\n\n\n\n<li>Fungsi untuk setiap operasi<\/li>\n\n\n\n<li>Validasi input (<code>try-except<\/code>)<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Contoh Kode Kalkulator Sederhana:<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>import tkinter as tk\n\ndef hitung(operator):\n    try:\n        a = float(entry1.get())\n        b = float(entry2.get())\n        if operator == \"+\":\n            hasil = a + b\n        elif operator == \"-\":\n            hasil = a - b\n        elif operator == \"*\":\n            hasil = a * b\n        elif operator == \"\/\":\n            if b == 0:\n                hasil = \"Tidak bisa dibagi nol!\"\n            else:\n                hasil = a \/ b\n        label_hasil.config(text=f\"Hasil: {hasil}\")\n    except ValueError:\n        label_hasil.config(text=\"Input harus angka!\")\n\n# GUI setup\nwindow = tk.Tk()\nwindow.title(\"Kalkulator GUI\")\nwindow.geometry(\"300x250\")\n\ntk.Label(window, text=\"Angka 1\").pack()\nentry1 = tk.Entry(window)\nentry1.pack()\n\ntk.Label(window, text=\"Angka 2\").pack()\nentry2 = tk.Entry(window)\nentry2.pack()\n\n# Tombol operasi\nframe = tk.Frame(window)\nframe.pack(pady=10)\n\ntk.Button(frame, text=\"+\", width=5, command=lambda: hitung(\"+\")).grid(row=0, column=0)\ntk.Button(frame, text=\"-\", width=5, command=lambda: hitung(\"-\")).grid(row=0, column=1)\ntk.Button(frame, text=\"\u00d7\", width=5, command=lambda: hitung(\"*\")).grid(row=0, column=2)\ntk.Button(frame, text=\"\u00f7\", width=5, command=lambda: hitung(\"\/\")).grid(row=0, column=3)\n\n# Label hasil\nlabel_hasil = tk.Label(window, text=\"Hasil: \")\nlabel_hasil.pack()\n\n# Tombol keluar\ntk.Button(window, text=\"Keluar\", command=window.quit).pack(pady=5)\n\nwindow.mainloop()<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Struktur Program yang Akan Dibuat: Contoh Kode Kalkulator Sederhana:<\/p>\n","protected":false},"author":1,"featured_media":20,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6,9,7],"tags":[],"class_list":["post-163","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-programming","category-projek","category-python"],"_links":{"self":[{"href":"https:\/\/learn.rantissi.my.id\/index.php\/wp-json\/wp\/v2\/posts\/163","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/learn.rantissi.my.id\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/learn.rantissi.my.id\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/learn.rantissi.my.id\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/learn.rantissi.my.id\/index.php\/wp-json\/wp\/v2\/comments?post=163"}],"version-history":[{"count":1,"href":"https:\/\/learn.rantissi.my.id\/index.php\/wp-json\/wp\/v2\/posts\/163\/revisions"}],"predecessor-version":[{"id":164,"href":"https:\/\/learn.rantissi.my.id\/index.php\/wp-json\/wp\/v2\/posts\/163\/revisions\/164"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/learn.rantissi.my.id\/index.php\/wp-json\/wp\/v2\/media\/20"}],"wp:attachment":[{"href":"https:\/\/learn.rantissi.my.id\/index.php\/wp-json\/wp\/v2\/media?parent=163"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/learn.rantissi.my.id\/index.php\/wp-json\/wp\/v2\/categories?post=163"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/learn.rantissi.my.id\/index.php\/wp-json\/wp\/v2\/tags?post=163"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}