本文實例講述了Python基於Tkinter實現的記事本。分享給大家供大家參考。具體如下:
?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 from Tkinter import * root = Tk('Simple Editor') mi=StringVar() Label(text='Please input something you like~' ).pack() te = Text(height = 30,width =100) te.pack() Label(text=' File name ').pack(side = LEFT) Entry(textvariable = mi).pack(side = LEFT) mi.set('*.txt') def save(): t = te.get('0.0','10.0') f = open(mi.get(),'w') f.write(t) Button(text = 'Save' , command = save).pack(side = RIGHT) Button(text = 'Exit' , command = root.quit).pack(side = RIGHT) mainloop()希望本文所述對大家的Python程序設計有所幫助。