The title is long and Sumimasen !!!!! It's difficult to summarize what you want to write ... Someone please give me a draft ... (By the way, it's been a long time since then. Please use the table of contents.) Also, please note that it is ** in the middle of writing **.
Source:Free encyclopedia "Wikipedia"
Tkinter is a standard library (widget toolkit) for building and manipulating GUIs from Python.
Tcl/The Tk part of Tk is made available in Python, and Tcl is used as much as possible./It is made to match Tk.
This makes it possible to easily create an application with a GUI screen from Python, which is a scripting language.
(The following is omitted)
It is written on Wikipedia, but well, to put it simply
GUI creation library that comes standard with Python
Is. The important thing is the "standard". You can create an application just by installing python (or using Pyinstaller) (without using other libraries). If anything, you can use Pyarmor to protect your source code.
#With Python2...
import Tkinter #tkinter body
import ttk #tkinter extension(?)
#With Python3...
import tkinter #tkinter body
from tkinter import ttk #tkinter extension(?)
Note that the module names are different between Python 2 and 3. By the way, if you write as follows, you can handle a few cars.
try:
import Tkinter as tkinter
import ttk
except:
import tkinter
from tkinter import ttk
By the way, "ttk", which has appeared from a while ago, is an extension (?) Of tkinter. You can use this to change the style (theme).
Next, create the main window.
root = tkinter.Tk()#Read carefully after this
However, if this is left as it is, the application name on the taskbar will be displayed as "Tk" on OS such as Ubuntu, so it is not good.
root = tkinter.Tk(className="[app name]")
And.
sub = tkinter.TopLevel()
And.
root.attributes("-fullscreen", True)
When returning
root.attributes("-fullscreen", False)
def callback():
print("Hello!!")
button = ttk.Button(root, text="[Text to display]",command=callback)
For command, specify the ** name ** of the function to be executed when the button is pressed. If you want to specify an argument,
def callback(hogehoge):
print(hogehoge)
button = ttk.Button(root, text="[Text to display]",command=lambda: callback("Hello!!!"))
frame = ttk.Frame(root)
Well ... frame is used by putting it in the root part of windows and other widgets. If you like, you can change the color and shape. (I will add it later.) An example of utilization is shown below.
def callback(hogehoge):
print(hogehoge)
frame = ttk.Frame(root)
button = ttk.Button(frame, text="[Text to display]",command=lambda: callback("Hello!!!"))
label = ttk.Label(root, text="[Text to display]")
In tkinter, you need to ** deploy ** after defining the widget. There are three placement methods.
In the packing method (pack), the widget is placed in an empty space of the window. (vocabulary...)
[Widget].pack([option])
[Widget] is an instance of the widget, (If you're crazy about instances and functions, check out the other Python introductory articles.) The following can be specified for [Option](it does not matter if nothing is specified): ・ Side You can set which direction to place it. Configurable value: "right" right, "left" left, "bottom" bottom, "top" top ・ Fill You can set which direction to fill. Configurable value: "both"-both directions "x"-x direction (vertical?) "y" -y direction (horizontal?) (Honestly, I'm worried, so I'd appreciate it if you could experiment and tell me.) ・ Anchor You can set where to place it. (Similar to side, but more specific) Configurable value: Well ... it's like this. (Quoted from here) nw --- n --- ne | | w c e | | sw --- s --- se ・ Expand You can set whether to fill in when blanks are created (for example, when the window size changes) Configurable value: True or False (It's because of my mind that the annoying odor is exposed ... it's true ...)
http://www.nct9.ne.jp/m_hiroi/light/python3.html#python3_tkinter