Selamat Datang PythonMania

Contoh program Selamat Datang dengan GUI Tkinter:

# file: selamat_datang.py

from Tkinter import *

class DemoSelamatDatang:
	def __init__(self, parent, title):
		self.parent = parent

		self.parent.title(title)
		self.parent.protocol("WM_DELETE_WINDOW", self.onKeluar)

		self.aturKomponen()

	def aturKomponen(self):
		mainFrame = Frame(self.parent, bd=10)
		mainFrame.pack(fill=BOTH, expand=YES)

		# pasang kotak edit
		self.entPesan = Entry(mainFrame, width=25)
		self.entPesan.insert(0, "Selamat Datang PythonMania")
		self.entPesan.pack(side=TOP, pady=5)

		# pasang tombol keluar
		self.btnKeluar = Button(mainFrame, text="Keluar",
			command=self.onKeluar)
		self.btnKeluar.pack(side=TOP, pady=5)

	def onKeluar(self, event=None):
		self.parent.destroy()

if __name__ == '__main__':
	root = Tk()

	aplikasi = DemoSelamatDatang(root, "Demo Tkinter")

	root.mainloop()

Inilah hasil-nya….

2 comments

  1. halo pak,
    maaf mau nanya, sekalipun saya copy paste tetap saja tidak bisa running.

    Traceback (most recent call last):
    File “C:\Users\Parlin\Documents\python Save\TKINTER 1.py”, line 1, in
    from Tkinter import *
    ImportError: No module named ‘Tkinter’

    Error code nya, dan saya menggunakan Python GUI 3.4.2

    Mohon bantuannya, baru belajar.

    Terimakasih

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s