user interface - How to create a UI in Python -
so have code...
name = raw_input("full name: ")
and supposed allow me type in name , use name activate "if" statements. however, want have program open window, simple gui, can type word. experience creating gui in java , through processing, lost when comes python. appreciated.
for start suggest start tkinter library (built in library).
this simple program using tkinter gui.
import tkinter class simpleapp_tk(tkinter.tk): def __init__(self,parent): tkinter.tk.__init__(self,parent) self.parent = parent self.initialize() def initialize(self): self.grid() self.entryvariable = tkinter.stringvar() self.entry = tkinter.entry(self,textvariable=self.entryvariable) self.entry.grid(column=0,row=0,sticky='ew') self.entry.bind("<return>", self.onpressenter) self.entryvariable.set(u"enter text here.") button = tkinter.button(self,text=u"click me !", command=self.onbuttonclick) button.grid(column=1,row=0) self.labelvariable = tkinter.stringvar() label = tkinter.label(self,textvariable=self.labelvariable, anchor="w",fg="white",bg="blue") label.grid(column=0,row=1,columnspan=2,sticky='ew') self.labelvariable.set(u"hello !") self.grid_columnconfigure(0,weight=1) self.resizable(true,false) self.update() self.geometry(self.geometry()) self.entry.focus_set() self.entry.selection_range(0, tkinter.end) def onbuttonclick(self): self.labelvariable.set( self.entryvariable.get()+" (you clicked button)" ) self.entry.focus_set() self.entry.selection_range(0, tkinter.end) def onpressenter(self,event): self.labelvariable.set( self.entryvariable.get()+" (you pressed enter)" ) self.entry.focus_set() self.entry.selection_range(0, tkinter.end) if __name__ == "__main__": app = simpleapp_tk(none) app.title('my application') app.mainloop()
the code taken http://sebsauvage.net/python/gui/ , tutorial.
Comments
Post a Comment