# data[].attributes.body
from tkinter import *

class App(Tk):
def __init__(self):
self.root = Tk()
self.root.title("BMI Calculator")
self.root.geometry('540x300')
self.root.configure(background='Indigo')
Tk.__init__(self)

# Sets a label and entry field into the window for weight, height in
# feet, and height in inches
self.label = Label(self.root, text="Enter your weight in kilogrammes.")
self.label.config(font = ("Narkisim", 16), relief = ("raised"))
self.label.pack()
self.kg = StringVar()
Entry(self.root, textvariable=self.kg).pack()

self.label = Label(self.root, text="Enter your height in metres.")
self.label.config(font = ("Narkisim", 16), relief = ("raised"))
self.label.pack()
self.metre = StringVar()
Entry(self.root, textvariable=self.metre).pack()

self.label = Label(self.root, text="Enter your height in centimetres.")
self.label.config(font = ("Narkisim", 16), relief = ("raised"))
self.label.pack()
self.centimetre = StringVar()
Entry(self.root, textvariable=self.centimetre).pack()

# Sets a button and label to click and calculate BMI
self.buttontext = StringVar()
Button(self.root, textvariable=self.buttontext, command=self.calculate).pack()
self.buttontext.set("Calculate")

# Sets bmi_num to a StringVar so that when it is changed, the label will
# update
self.bmi_num = StringVar()
Label(self.root, textvariable=self.bmi_num).pack()

# Same thing here
self.bmi_text = StringVar()
Label(self.root, textvariable=self.bmi_text).pack()

self.root.mainloop()

def calculate(self):
# Retrieves all necessary information to calculate BMI
weight = float(self.kg.get())
metre = float(self.metre.get())
centimetre = float(self.centimetre.get())
height = (metre*100)+centimetre
bmi = float((weight*10000)/(height**2))
# Updates the status label
self.bmi_num.set("Your BMI is %.2f" % bmi)
if bmi < 18.5:
self.bmi_text.set("You are underweight")
if 18.5 <= bmi < 25:
self.bmi_text.set("You are normal")
if 25 <= bmi < 30:
self.bmi_text.set("You are overweight")
if 30<= bmi > 30:
self.bmi_text.set("You are obese")

App()

# data[].attributes.body
from tkinter import*
from tkinter import*
from tkinter.ttk import*
gambar=PhotoImage(file="images.png")
window = Tk()

def kira_perimeter():
jejari = int(strTxtjejari.get())
luas = int(strTxtluas.get())
perimeter = luas*2*3.14
strTxtperimeter.set(str(perimeter))

def kosongkan():
strTxtjejari.set ("")
strTxtluas.set ("")
strTxtperimeter.set ("")

lbljejari = Label (window, text = "Jejari(cm)")
lbljejari.place (x=100, y=40)

lbljejari  = Label (window, text = "Luas(cm)")
lbljejari.place (x=100, y=80)

lbljejari  = Label (window, text = "Perimeter(cm)")
lbljejari.place (x=100, y=120)

strTxtjejari= StringVar()
txtjejari = Entry (window, textvariable=strTxtjejari)
txtjejari.place (x=200, y=40, width = 50, height = 20)

strTxtluas = StringVar()
txtluas = Entry (window, textvariable=strTxtluas)
txtluas.place (x=200, y=80, width = 50, height = 20)

strTxtperimeter = StringVar()
txtperimeter = Entry (window, textvariable=strTxtperimeter)
txtperimeter.place (x=200, y=120, width = 50, height = 20)

btnKira = Button (window, text = "Kira", command = kira_perimeter)
btnKosongkan =Button (window, text = "Kosongkan", command = kosongkan)
btnKeluar = Button (window, text = "Keluar", command = window.destroy)

btnKira.place (x=30, y=200, width = 90, height = 40)
btnKosongkan.place (x=150, y=200, width = 90, height = 40)
btnKeluar.place (x=270, y=200, width = 90, height = 40)

window.title ("Mencari Perimeter Bulatan")
window.geometry ("400x300")
lblgambar1=Label(window)
lblgambar.place(x=900, y=180)

# data[].attributes.body
from tkinter import*
from tkinter.ttk import*

window = Tk()

def kira_berat():
berat = int(strTxtBerat.get())
tinggi = int(strTxtTinggi.get())
BMI = berat * tinggi * tinggi
strTxtBMI.set(str(BMI))

def kosongkan():
strTxtBerat.set ("")
strTxtTinggi.set ("")
strTxtBMI.set ("")

lblBerat = Label (window, text = "Berat")
lblBerat .place (x=100, y=40)

lblBerat  = Label (window, text = "Tinggi")
lblBerat .place (x=100, y=80)

lblBerat  = Label (window, text = "BMI")
lblBerat .place (x=100, y=120)

strTxtBerat= StringVar()
txtBerat = Entry (window, textvariable=strTxtBerat)
txtBerat.place (x=200, y=40, width = 50, height = 20)

strTxtTinggi = StringVar()
txtTinggi = Entry (window, textvariable=strTxtTinggi)
txtTinggi.place (x=200, y=80, width = 50, height = 20)

strTxtBMI = StringVar()
txtBMI = Entry (window, textvariable=strTxtBMI)
txtBMI.place (x=200, y=120, width = 50, height = 20)

btnKira = Button (window, text = "Kira", command = kira_berat)
btnKosongkan =Button (window, text = "Kosongkan", command = kosongkan)
btnKeluar = Button (window, text = "Keluar", command = window.destroy)

btnKira.place (x=30, y=200, width = 90, height = 40)
btnKosongkan.place (x=150, y=200, width = 90, height = 40)
btnKeluar.place (x=270, y=200, width = 90, height = 40)

window.title ("Mencari Luas Segi Empat")
window.geometry ("400x300")

# data[].attributes.attachment_link.readable_text
from tkinter import*
from tkinter.ttk import*

window = Tk()

def kira_luas():
    panjang = int(strTxtPanjang.get())
    lebar = int(strTxtLebar.get())
    luas = panjang * lebar 
    strTxtLuas.set(str(luas))
    
def kosongkan():
    strTxtPanjang.set ("")
    strTxtLebar.set ("")
    strTxtLuas.set ("")
    
lblPanjang = Label (window, text = "Panjang")
lblPanjang.place (x=100, y=40)

lblPanjang = Label (window, text = "Lebar")
lblPanjang.place (x=100, y=80)

lblPanjang = Label (window, text = "Luas")
lblPanjang.place (x=100, y=120)

strTxtPanjang = StringVar()
txtPanjang = Entry (window, textvariable=strTxtPanjang)
txtPanjang.place (x=200, y=40, width = 50, height = 20)

strTxtLebar = StringVar()
txtLebar = Entry (window, textvariable=strTxtLebar)
txtLebar.place (x=200, y=80, width = 50, height = 20)

strTxtLuas = StringVar()
txtLuas = Entry (window, textvariable=strTxtLuas)
txtLuas.place (x=200, y=120, width = 50, height = 20)

btnKira = Button (window, text = "Kira", command = kira_luas)
btnKosong =Button (window, text = "Kosongkan", command = kosongkan)
btnKeluar = Button (window, text = "Keluar", command = quit)

btnKira.place (x=30, y=200, width = 90, height = 40)
btnKosong.place (x=150, y=200, width = 90, height = 40)
btnKeluar.place (x=270, y=200, width = 90, height = 40)

window.title ("Mencari Luas Segi Empat")
window.geometry ("400x300")

# data[].attributes.body
import tkinter as tk                # python 3
from tkinter import font  as tkfont # python 3
#import Tkinter as tk     # python 2
#import tkFont as tkfont  # python 2

class SampleApp(tk.Tk):

def __init__(self, *args, **kwargs):
tk.Tk.__init__(self, *args, **kwargs)

self.title_font = tkfont.Font(family='Helvetica', size=18, weight="bold", slant="italic")

# the container is where we'll stack a bunch of frames
# on top of each other, then the one we want visible
# will be raised above the others
container = tk.Frame(self)
container.pack(side="top", fill="both", expand=True)
container.grid_rowconfigure(0, weight=1)
container.grid_columnconfigure(0, weight=1)

self.frames = {}
for F in (StartPage, PageOne, PageTwo):
page_name = F.__name__
frame = F(parent=container, controller=self)
self.frames[page_name] = frame

# put all of the pages in the same location;
# the one on the top of the stacking order
# will be the one that is visible.
frame.grid(row=0, column=0, sticky="nsew")

self.show_frame("StartPage")

def show_frame(self, page_name):
'''Show a frame for the given page name'''
frame = self.frames[page_name]
frame.tkraise()

class StartPage(tk.Frame):

def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
self.controller = controller
label = tk.Label(self, text="This is the start page", font=controller.title_font)
label.pack(side="top", fill="x", pady=10)

button1 = tk.Button(self, text="Go to Page One",
command=lambda: controller.show_frame("PageOne"))
button2 = tk.Button(self, text="Go to Page Two",
command=lambda: controller.show_frame("PageTwo"))
button1.pack()
button2.pack()

class PageOne(tk.Frame):

def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
self.controller = controller
label = tk.Label(self, text="This is page 1", font=controller.title_font)
label.pack(side="top", fill="x", pady=10)
button = tk.Button(self, text="Go to the start page",
command=lambda: controller.show_frame("StartPage"))
button.pack()

class PageTwo(tk.Frame):

def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
self.controller = controller
label = tk.Label(self, text="This is page 2", font=controller.title_font)
label.pack(side="top", fill="x", pady=10)
button = tk.Button(self, text="Go to the start page",
command=lambda: controller.show_frame("StartPage"))
button.pack()

if __name__ == "__main__":
app = SampleApp()
app.mainloop()

# data[].attributes.body
Version:1.0 StartHTML:000000243 EndHTML:000026950 StartFragment:000010277 EndFragment:000026838 StartSelection:000010277 EndSelection:000026838 SourceURL:https://stackoverflow.com/questions/7546050/switch-between-two-frames-in-tkinter python - Switch between two frames in tkinter - Stack Overflow      &lt;style&gt;body,.top-bar{margin-top:1.9em}&lt;/style&gt;

import tkinter as tk                # python 3
from tkinter import font  as tkfont # python 3
#import Tkinter as tk     # python 2
#import tkFont as tkfont  # python 2

class SampleApp(tk.Tk):

def __init__(self, *args, **kwargs):
tk.Tk.__init__(self, *args, **kwargs)

self.title_font = tkfont.Font(family='Helvetica', size=18, weight="bold", slant="italic")

# the container is where we'll stack a bunch of frames
# on top of each other, then the one we want visible
# will be raised above the others
container = tk.Frame(self)
container.pack(side="top", fill="both", expand=True)
container.grid_rowconfigure(0, weight=1)
container.grid_columnconfigure(0, weight=1)

self.frames = {}
for F in (StartPage, PageOne, PageTwo):
page_name = F.__name__
frame = F(parent=container, controller=self)
self.frames[page_name] = frame

# put all of the pages in the same location;
# the one on the top of the stacking order
# will be the one that is visible.
frame.grid(row=0, column=0, sticky="nsew")

self.show_frame("StartPage")

def show_frame(self, page_name):
'''Show a frame for the given page name'''
frame = self.frames[page_name]
frame.tkraise()

class StartPage(tk.Frame):

def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
self.controller = controller
label = tk.Label(self, text="This is the start page", font=controller.title_font)
label.pack(side="top", fill="x", pady=10)

button1 = tk.Button(self, text="Go to Page One",
command=lambda: controller.show_frame("PageOne"))
button2 = tk.Button(self, text="Go to Page Two",
command=lambda: controller.show_frame("PageTwo"))
button1.pack()
button2.pack()

class PageOne(tk.Frame):

def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
self.controller = controller
label = tk.Label(self, text="This is page 1", font=controller.title_font)
label.pack(side="top", fill="x", pady=10)
button = tk.Button(self, text="Go to the start page",
command=lambda: controller.show_frame("StartPage"))
button.pack()

class PageTwo(tk.Frame):

def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
self.controller = controller
label = tk.Label(self, text="This is page 2", font=controller.title_font)
label.pack(side="top", fill="x", pady=10)
button = tk.Button(self, text="Go to the start page",
command=lambda: controller.show_frame("StartPage"))
button.pack()

if __name__ == "__main__":
app = SampleApp()
app.mainloop()

# data[].attributes.body
import tkinter as tk

def write_slogan():
print("Tkinter is easy to use!")

root = tk.Tk()
frame = tk.Frame(root)
frame.pack()

button = tk.Button(frame,
text="QUIT",
fg="red",
command=quit)
button.pack(side=tk.LEFT)
slogan = tk.Button(frame,
text="Hello",
command=write_slogan)
slogan.pack(side=tk.LEFT)

root.mainloop()

# data[].attributes.body
import Tkinter as tk

counter = 0
def counter_label(label):
  counter = 0
  def count():
    global counter
    counter += 1
    label.config(text=str(counter))
    label.after(1000, count)
  count()


root = tk.Tk()
root.title("Counting Seconds")
label = tk.Label(root, fg="dark green")
label.pack()
counter_label(label)
button = tk.Button(root, text='Stop', width=25, command=root.destroy)
button.pack()
root.mainloop()

# data[].attributes.body
from tkinter import*
from tkinter.ttk import*
window = Tk()

ans = ""
noSoalan = -1
Mark = 0

senarai_soalan = ["Di manakah terletaknya Kota Raja Mahadi?\nA.Selangor\nB.Melaka\nC.Pahang",
"Pulau apakah yang paling besar di Malaysia?\nA.Pulau Tioman, Pahang\nB. Pulau Banggi, Sabah\nC. Pulau Langkawi, Kedah",
"Negeri manakah yang paling besar di Malaysia?\nA. Pahang\nB. Sarawak\nC. Johor",
"Apakah kaum yang terkecil di Malaysia?\nA. Kadazandusun\nB. Iban\nC. Ceti",
"Siapakah pencipta Jalur Gemilang?\nA. Mohamed Hamzah\nB. Muhammad Arif Fakhruddin\nC. Ishak bin Haji Muhammad",
"Siapakah Chief Operator Officer(COO) syarikat yang mencipta Facebook?\nA. Mark Zuckerberg\nB. David Wehner\nC. Sheryl Sandberg",
"Bilakah Tunku Abdul Rahman dilahirkan?\nA. 1902\nB. 1903\nC. 1904",
"Siapakah arkitek pembinaan Menara Berkembar Petronas?\nA. César Pelli\nB. Fernandez Garcia\nC. Diego Sanchez",
"Apakah kereta pertama yang diciptakan di Malaysia?\nA. Proton Wira\nB. Proton Satria\nC. Proton Saga",
"Bilakah Malaysia ditubuhkan?\nA. 1957\nB. 1963\nC. 1964",
"Negara apakah yang menawan Malaysia ketika Perang Dunia II?\nA. Portugis\nB. Jepun\nC. British",
"Siapakah pengasas Microsoft?\nA. Bill Gates\nB. Steve Ballmer\nC. Steve Jobs",
"Apakah negara yang paling terkecil di dunia?\nA. Timor Leste\nB. Vatican City\nC. Liechtenstein",
"Apakah negara yang paling kaya di dunia?\nA. Qatar\nB. Singapore\nC. Luxembourg",
"Siapakah Adolf Hitler?\nA. Pengeluar kasut berjenama\nB.Ketua Nazi\nC. Penjual 'Hotdog' terlaris di Jerman"]
senarai_jawapan = ["a", "b", "b", "c", "a", "c", "b", "a", "c", "b", "b", "a", "b", "c", "b"]
senarai_jawapanCaps = ["A", "B", "B", "C", "A", "C", "B", "A", "C", "B", "B", "A", "B", "C", "B"]

def papar_soalan():
global noSoalan, Mark #

noSoalan = noSoalan + 1
if noSoalan == 15:
noSoalan = 0
Mark = 0
strLblMark.set("")

strLblMesej.set("")
strTxtJawab.set("")
txtJawab.focus()
strLblnoSoalan.set("Soalan" + str(noSoalan + 1))

strLblSoalan.set(senarai_soalan[noSoalan])
txtJawab.place(x=400, y=200, width= 100, height=20)

btnSemak.config(state=NORMAL)
btnSoalan.config(state=DISABLED)

def semak_jawapan():
global Mark
jawapan_pengguna = strTxtJawab.get()
if senarai_jawapan[noSoalan] == jawapan_pengguna or senarai_jawapanCaps[noSoalan] == jawapan_pengguna :
strLblMesej.set("Tahniah, Jawapan Anda Tepat")
Mark = Mark + 2
else :
strLblMesej.set("Sila Cuba Lagi")

strLblMark.set("Mark : " + str(Mark) + "/30")
btnSemak.config(state=DISABLED)
btnSoalan.config(state=NORMAL)

strLblMesej = StringVar()
lblMesej = Label(window, textvariable = strLblMesej)
lblMesej.config(font = ("Comic Sans MS", 16),foreground="black")
lblMesej.place(x = 50, y = 190)

strLblMark = StringVar()
lblMark = Label(window, textvariable = strLblMark)
lblMark.config(font = ("Comic Sans MS", 16), foreground = "orange")
lblMark.place(x = 350, y = 20)

strLblnoSoalan = StringVar()
lblnoSoalan = Label(window, textvariable = strLblnoSoalan)
lblnoSoalan.config(font = ("Franklin Gothic Medium Cond", 16), foreground = "magenta")
lblnoSoalan.place(x = 50, y = 20)

strLblSoalan = StringVar()
lblSoalan = Label(window, textvariable = strLblSoalan)
lblSoalan.config(font = ("Arial", 16), foreground = "blue")
lblSoalan.place(x = 50, y = 50)

strTxtJawab = StringVar()
txtJawab = Entry(window, textvariable = strTxtJawab)

btnSoalan = Button(window, text="Soalan Seterusnya", command = papar_soalan )
btnSoalan.config(state=NORMAL)
btnSemak = Button(window, text="Semak", command = semak_jawapan)
btnSemak.config(state=DISABLED)
btnKeluar = Button(window, text="Keluar", command = quit)

btnSoalan.place(x=50, y=230, width=130, height=40)
btnSemak.place(x=240, y=230, width=90, height=40)
btnKeluar.place(x=400, y=230, width=90, height=40)

window.title("Kuiz Pengetahuan Am")
window.geometry('540x300')

window.mainloop()

# data[].attributes.body
from tkinter import*
from tkinter.ttk import*
window = Tk()

def hello():
strLblOutput.set("Assalamualaikum")
#strLblOutput.configure(font=("Comic Sans",  16), foreground="blue")

def hello2():
strLblOutput.set("Waalaikumussalam")
#strLblOutput.configure(font=("Comic Sans",  16), foreground="blue")

strLblOutput = StringVar()
lblOutput=Label(window, textvariable=strLblOutput, anchor="center", relief="sunken")#relief can be = raised, flat , ridge, groove, solid
lblOutput.place(x=30 , y=20, width=340, height =300) #lokasi strLblOutput
lblOutput.configure(font=("Comic Sans MS",  16), foreground="Black")

btnPapar = Button(window, text="Beri Salam", command = hello)#command = arahan
btnPapar.place(x=60, y=350, width=80,height=40)

btnPapar = Button(window, text="Jawab Salam", command = hello2)#command = arahan
btnPapar.place(x=160, y=350, width=80,height=40)

btnPapar = Button(window, text="Keluar", command =sys.exit)#command = arahan
btnPapar.place(x=260, y=350, width=80,height=40)