Creating Simple window in tkinter

Previous
Next
  • We need to import Tk class from tkinter module.
  • Instantiation of Tk class results a “window.
  • The following code snippet display the frame with title ‘tk’
from tkinter import Tk

class GUI:
    def main():
        frame = Tk()
        return

GUI.main()
  • We can write GUI programs without using classes(object orientation).
  • mainloop()is used to represent the execution point(when multiple frames) of application.
  • When we define the code in single frame, calling mainloop() is optional.
from tkinter import Tk
frame = Tk()
frame.mainloop()

Using the pre-defined functionality of “Tk” class, we can set properties to Frame.

from tkinter import Tk
frame = Tk()
frame.title("GUI")
frame.geometry("500x300")
frame.mainloop()
Previous
Next

Add Comment

Courses Enquiry Form