Create desktop applications with Python tkinter
You can create desktop apps with Python. The desktop app can have one or multiple windows and can contain components which are called widgets.
For example, the Python desktop program below creates two buttons and a label. Tkinter has many widgets you can add to a window, labels and buttons being just one of them.
from tkinter import *class OnOffButton(Button):
def __init__(self,master=None,text=None):
Button.__init__(self,master,text=text)
self['command'] = self._onButtonClick def _onButtonClick(self):
print('button clicked')
class App(Frame):
def __init__(self,master=None):
Frame.__init__(self,master) self.labelHello = Label(self,text="Hello World")
self.labelHello['fg'] = "red"
self.labelHello.grid() self.button1 = OnOffButton(self,text="Click Me")
self.button1.grid() self.button2 = OnOffButton(self,text="Click me?")
self.button2.grid()def main():
root = Tk()
app = App(master=root)
app.grid()
root.mainloop()if __name__ == '__main__':
main()
In this example there are 3 widgets: a label and a button. You can create a label by calling
Label(self,text="Hello World")
To create a button, call (the class is subclassed)
Button(self,text="Click me?")
So you can make all kinds of desktop apps with tkinter. But you can create “graphical apps”, similar to Paint.
These are just simple examples. You can create much more complex graphical user interfaces, as shown in the image below:
More reading:
0 comentarios:
Publicar un comentario