Ok, this time we are going to talk about the tkinter module, a module to make GUIs (graphic user interface) for Python. Until now we have just used the console or the jupyter nootebook (and its widgets) to show the output. Now we are going to use the usual windows for linux, windows or MacOs.
1. IMPORT THE MODULE
To use the tkinter modules (on python 3) you have to import them, for example, like this:
from tkinter import *
In this way you don't have to write tkinter. and then the classes you are going to use, but just the name of the classes. It is "faster", but it can sometime coflict with other names of other modules you can import. For now, we will use this way to import tkinter, anyway.
2. CREATE A WINDOW
root = Tk()
root.geometry("400x300+500+300")
root.mainloop()
About the geometry method of root (istance of Tk()): We passed a string argument to the method:
- 400x300 is the size of the window
- 500+300 are the position of window on the screen
root.mainloop() takes the window on a loop as it can be easily understood.
The Jupyter notebook
Comments
Post a Comment