Created
March 22, 2017 07:19
-
-
Save ekojs/d43a7eeae5234b5886bf51ef82510384 to your computer and use it in GitHub Desktop.
Sample Program using TKInter Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from Tkinter import * | |
from tkMessageBox import * | |
from tkSimpleDialog import * | |
class Application(Frame): | |
def say_hi(self): | |
try: | |
with open("list_nama.txt", "r") as f: | |
for x in f: | |
print "Hallo %s!" %(x.replace("\n","") if x != "" else "everyone"); | |
except IOError as e: | |
print 'Tidak ada List Nama !!!'; | |
def tes(self): | |
showinfo("Hallo bro","Contoh simpan nama"); | |
self.name = askstring("Nama", "Siapa nama anda ?"); | |
self.lbl_tes["text"] = "Hallo %s" %(self.name); | |
with open("list_nama.txt", "a") as f: | |
f.write(self.name+"\n"); | |
def createWidgets(self): | |
self.lbl_tes = Label(self); | |
self.lbl_tes["text"] = "Sample Program"; | |
self.QUIT = Button(self); | |
self.QUIT["text"] = "QUIT"; | |
self.QUIT["fg"] = "red"; | |
self.QUIT["command"] = self.quit; | |
self.hi_there = Button(self); | |
self.hi_there["text"] = "Hello"; | |
self.hi_there["command"] = self.say_hi; | |
self.btn_tes = Button(self); | |
self.btn_tes["text"] = "Simpan Nama"; | |
self.btn_tes["command"] = self.tes; | |
self.lbl_tes.pack({"side": "top"}); | |
self.QUIT.pack({"side": "left"}); | |
self.hi_there.pack({"side": "left"}); | |
self.btn_tes.pack({"side": "left"}); | |
def __init__(self, master=None): | |
Frame.__init__(self, master); | |
self.pack(); | |
self.createWidgets(); | |
root = Tk(); | |
app = Application(master=root); | |
app.mainloop(); | |
root.destroy(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment