Wednesday 25 March 2015

Creating Button

In this code samples it is shown how to create buttons in a simple way, albeit it could get complicated at the end.

The first go like this:

import Tkinter
root = Tkinter.Tk()
button = Tkinter.Button(root, text = "Forgotten Sign").pack()
root.mainloop()


Which ends up like this:




The other one is:

import Tkinter
root = Tkinter.Tk()
button1 = Tkinter.Button(root, text = "Forgotten Sign").pack()
button2 = Tkinter.Button(root, text = "Warning").pack()
root.mainloop()

And the result is:

The last one is making some order in it:

from Tkinter import *
root = Tk()
button1 = Button(root, text = "Forgotten Sign").pack(side = LEFT)
button2 = Button(root, text = "Warning").pack(side = LEFT)
root.mainloop()

Which gets like this:

Of course these buttons just are clickable, this is because we haven't put any other stuff like commands or any other decoration, which is why the code is so compact and without changing the title of the window program :P

No comments:

Post a Comment