First of all this is a collection of codes that are found in different tutorials related to Python GUI with
TKinter. It's going to be used Python 2.7 and PyScripter, some people preffer other options than Pyscripter, like PyCharm, it's a matter of tastes. There are different ways in wihch one could use TKinter in Python, some are really practical and other are a little bit fancy, of course one must see those pieces of code before telling this or that right away, so let's see some of them.
TKinter. It's going to be used Python 2.7 and PyScripter, some people preffer other options than Pyscripter, like PyCharm, it's a matter of tastes. There are different ways in wihch one could use TKinter in Python, some are really practical and other are a little bit fancy, of course one must see those pieces of code before telling this or that right away, so let's see some of them.
The first one
is considered not so wise because in the line that import Tkinter, well, this line will import everything from Tkinter and the code could get messy if we are importing from other libraries too, so you get the picture (well, maybe not, if that's the case, you could get a little bit more of information about that in "Why import star is a bad idea ")
from Tkinter import *
root = Tk()
theLoneLabel = Label(root, text = "About time!")
theLoneLabel.pack()
root.mainloop()
When you run the previous code,
it would just show text in a label inside a little window that TKinter creates,
and notice that the tittle hasn't been edited so we will find that the tittle says "tk", just that two words, that's because we never messed with the tittle properties.
The second one
is considered to be more easy to handle along with other imported libraries because in this case we're just importing parts from Tkinter, just the ones that we need and nothing more.
from Tkinter import Label, mainloop
Label(text = "About Time!").pack()
mainloop()
This last code is supposed to do the same than the first one,
of course there are some similarities, but the last one it's more compact, yeah!
No comments:
Post a Comment