Tikinter Python
Some Basic Intro:Most of the time, the
Tkinter
module is all you really need, but a number of additional modules are available as well. The Tk interface is located in a binary module named _tkinter
. This module contains the low-level interface to Tk, and should never be used directly by application programmers. It is usually a shared library (or DLL), but might in some cases be statically linked with the Python interpreter.In addition to the Tk interface module,
Tkinter
includes a number of Python modules. The two most important modules are the Tkinter
module itself, and a module called Tkconstants
. The former automatically imports the latter, so to use Tkinter, all you need to do is to import one module:import Tkinter
from Tkinter import *
- class
Tkinter.
Tk
(screenName=None, baseName=None, className='Tk', useTk=1)¶ - The
Tk
class is instantiated without arguments. This creates a toplevel widget of Tk which usually is the main window of an application. Each instance has its own associated Tcl interpreter.
Changed in version 2.4: The useTk parameter was added.
Tkinter.
Tcl
(screenName=None, baseName=None, className='Tk', useTk=0)¶- The
Tcl()
function is a factory function which creates an object much like that created by theTk
class, except that it does not initialize the Tk subsystem. This is most often useful when driving the Tcl interpreter in an environment where one doesn’t want to create extraneous toplevel windows, or where one cannot (such as Unix/Linux systems without an X server). An object created by theTcl()
object can have a Toplevel window created (and the Tk subsystem initialized) by calling itsloadtk()
method.
New in version 2.4.
Example of Tikinter Using Basic Lib
In this example we will see the use of button and label in python GUI Programme,
from tkinter import *
root=Tk()
# =============================================================================
# theLabel=Label(root,text="Too Easy")
# theLabel.pack()
topFrame=Frame(root)
topFrame.pack()
bottomFrame=Frame(root)
bottomFrame.pack(side=BOTTOM)
button1=Button(topFrame,text="Button 1",fg="red")
button2=Button(topFrame,text="Button 2",fg="blue")
button3=Button(topFrame,text="Button 3",fg="green")
button4=Button(bottomFrame,text="Button 4",fg="purple")
button1.pack(side=LEFT)
button2.pack(side=LEFT)
button3.pack(side=LEFT)
button4.pack(side=BOTTOM)
root.mainloop()
Output:
No comments:
Post a Comment