Python gui tkinter ต วอย าง ม อถ อ

  • คุณอยู่ที่:
  • บทเรียนออนไลน์
  • บทเรียน Python
  • บทเรียน - เขียนโปรแกรม เบื้องต้น
  • บทเรียน Python GUI
  • Tkinter (ทีเคอินเตอร์) คืออะไร

หมวดหลัก:บทเรียน - เขียนโปรแกรม เบื้องต้น หมวด:บทเรียน Python GUI

tkinter คืออะไร

Tkinter เป็นโมดูล อินเตอร์เฟซมาตรฐาน .Tk python Tk GUI Toolkit และ Tkinter สามารถใช้ได้มากที่สุดในแพลตฟอร์ม Unix เดียวกันสามารถนำไปใช้กับทั้งระบบ Windows และ Macintosh, Tk8.0

การเขียนโปรแกรม Tkinter

Tkinter เป็นโมดูลที่ทำให้ Python ทำ GUI ได้โดยใช้ความสามารถของ Tkinter สามารถสร้างโปรแกรม GUI

การสร้างโปรแกรมแบบ GUI

  1. โมดูลนำเข้า Tkinter
  2. สร้างการควบคุมทำหน้าจอและ action เรียกฟังก์ชั่นให้ทำงาน
  3. กำหนดต้นแบบการควบคุมที่เป็นตัวควบคุมที่พวกเขาอยู่
  4. บอกว่าจีเอ็ม (ผู้จัดการเรขาคณิต) มีการผลิตการควบคุม

โมดูล Tkinter

Tkinter ให้ความหลากหลายของการควบคุมเช่น ปุ่ม ป้ายและกล่องข้อความ , การใช้งานโปรแกรมประยุกต์แบบ GUI การควบคุมเหล่านี้มักจะเรียกว่าการควบคุมหรือส่วนประกอบ

Tkinter คือ GUI toolkit ที่ได้รับความนิยมและมีอายุมานาน โดยเริ่มจากภาษา Tcl และถูกพัฒนาต่อเนื่องมานาน โดยต้นฉบับแรกของ Tk ถูกสร้างขึ้นในปี 1991 โดย John Ousterhout. Tk ถูกออกแบบมาเพื่อให้สามารถใช้งานร่วมกับภาษาอื่นได้, ซึ่งนี่คือเหตุผลที่ทำให้มีการพัฒนา Tkinter สำหรับภาษา Python.

I am writing a Python program with a GUI and have selected tkinter to do so. I have some experience with Python, but I am new to tkinter and GUI programming.

I have been reading a few tutorials about how to use tkinter. What I could find was very basic, such as "how to display a button". This leaves me struggling to identify a useful model for structuring the part of my program that defines the UI.

So far my searches only yielded 1 guide for structuring a python/tkinter GUI in an OOP style: pythonprogramming.net

Although this is a welcome example and very helpful in its specificity, it seems to me as though the inheritance of tkinter classes and adding new unrelated code to those new classes violates a strict separation of concerns. It looks very convenient on the short term, but I can't tell if it has undesirable consequences long-term.

As an alternative I created another example, in which I made similar classes, but avoided inheriting from tkinter classes, by composing various tkinter objects. This keeps functionality separated with only a couple of additional methods.

I would appreciate feedback on which approach is more useful as a UI grows in complexity. This could include specific suggestions on other models to use, links to information on the subject, source code examples of programs using tkinter, and so on.

Python offers multiple options for developing GUI (Graphical User Interface). Out of all the GUI methods, tkinter is the most commonly used method. It is a standard Python interface to the Tk GUI toolkit shipped with Python. Python tkinter is the fastest and easiest way to create GUI applications. Creating a GUI using tkinter is an easy task.

To create a tkinter Python app:

  1. Importing the module – tkinter
  2. Create the main window (container)
  3. Add any number of widgets to the main window
  4. Apply the event Trigger on the widgets.

Importing a tkinter is the same as importing any other module in the Python code. Note that the name of the module in Python 2.x is ‘Tkinter’ and in Python 3.x it is ‘tkinter’.

import tkinter

There are two main methods used which the user needs to remember while creating the Python application with GUI.

  1. Tk(screenName=None, baseName=None, className=’Tk’, useTk=1): To create a main window, tkinter offers a method ‘Tk(screenName=None, baseName=None, className=’Tk’, useTk=1)’. To change the name of the window, you can change the className to the desired one. The basic code used to create the main window of the application is: m=tkinter.Tk() where m is the name of the main window object
  2. mainloop(): There is a method known by the name mainloop() is used when your application is ready to run. mainloop() is an infinite loop used to run the application, wait for an event to occur and process the event as long as the window is not closed.

    m.mainloop()

    Python

    m.mainloop() 0 m.mainloop() 1 m.mainloop() 2 m.mainloop() 3 m.mainloop() 4 m.mainloop() 5

Tkinter also offers access to the geometric configuration of the widgets which can organize the widgets in the parent windows. There are mainly three geometry manager classes class.

  1. pack() method:It organizes the widgets in blocks before placing in the parent widget.
  2. grid() method:It organizes the widgets in grid (table-like structure) before placing in the parent widget.
  3. place() method:It organizes the widgets by placing them on specific positions directed by the programmer.

There are a number of widgets which you can put in your tkinter application. Some of the major widgets are explained below:

  1. Button:To add a button in your application, this widget is used. The general syntax is:

    w=Button(master, option=value) master is the parameter used to represent the parent window. There are number of options which are used to change the format of the Buttons. Number of options can be passed as parameters separated by commas. Some of them are listed below.

    • activebackground: to set the background color when button is under the cursor.
    • activeforeground: to set the foreground color when button is under the cursor.
    • bg: to set the normal background color.
    • command: to call a function.
    • font: to set the font on the button label.
    • image: to set the image on the button.
    • width: to set the width of the button.
    • height: to set the height of the button.

      Python

      m.mainloop() 0 m.mainloop() 7 m.mainloop() 8 m.mainloop() 3 w=Button(master, option=value) 0 w=Button(master, option=value) 1 w=Button(master, option=value) 2 w=Button(master, option=value) 3 w=Button(master, option=value) 4 m.mainloop() 3 w=Button(master, option=value) 6 m.mainloop() 3 w=Button(master, option=value) 8 w=Button(master, option=value) 9 m.mainloop() 3 w = Canvas(master, option=value) master is the parameter used to represent the parent window. 1 w = Canvas(master, option=value) master is the parameter used to represent the parent window. 2 m.mainloop() 3 w = Canvas(master, option=value) master is the parameter used to represent the parent window. 4 w = Canvas(master, option=value) master is the parameter used to represent the parent window. 5 w = Canvas(master, option=value) master is the parameter used to represent the parent window. 6 Output:
  2. Canvas: It is used to draw pictures and other complex layout like graphics, text and widgets. The general syntax is:

    w = Canvas(master, option=value) master is the parameter used to represent the parent window. There are number of options which are used to change the format of the widget. Number of options can be passed as parameters separated by commas. Some of them are listed below.

    • bd: to set the border width in pixels.
    • bg: to set the normal background color.
    • cursor: to set the cursor used in the canvas.
    • highlightcolor: to set the color shown in the focus highlight.
    • width: to set the width of the widget.
    • height: to set the height of the widget.

      Python

      w = Canvas(master, option=value) master is the parameter used to represent the parent window. 7 w = Canvas(master, option=value) master is the parameter used to represent the parent window. 8 m.mainloop() 0 w = CheckButton(master, option=value) 0 w = CheckButton(master, option=value) 1 m.mainloop() 3 w = CheckButton(master, option=value) 3 w = CheckButton(master, option=value) 4 m.mainloop() 3 w = CheckButton(master, option=value) 6 m.mainloop() 3 w = CheckButton(master, option=value) 8 w = CheckButton(master, option=value) 9 m.mainloop() 3 w=Entry(master, option=value) 1 w=Button(master, option=value) 3 w=Entry(master, option=value) 3 w=Entry(master, option=value) 4 m.mainloop() 3 w=Entry(master, option=value) 6 w=Entry(master, option=value) 7 m.mainloop() 3 w=Entry(master, option=value) 9 w = Frame(master, option=value) master is the parameter used to represent the parent window. 0 m.mainloop() 3 w = Frame(master, option=value) master is the parameter used to represent the parent window. 2 w = Frame(master, option=value) master is the parameter used to represent the parent window. 3 w = Frame(master, option=value) master is the parameter used to represent the parent window. 4 w = Frame(master, option=value) master is the parameter used to represent the parent window. 5 w=Button(master, option=value) 3 w = Frame(master, option=value) master is the parameter used to represent the parent window. 7 w = Frame(master, option=value) master is the parameter used to represent the parent window. 8 w = Frame(master, option=value) master is the parameter used to represent the parent window. 9 w=Label(master, option=value) master is the parameter used to represent the parent window. 0 Output:
  3. CheckButton: To select any number of options by displaying a number of options to a user as toggle buttons. The general syntax is:

    w = CheckButton(master, option=value) There are number of options which are used to change the format of this widget. Number of options can be passed as parameters separated by commas. Some of them are listed below.

    • Title: To set the title of the widget.
    • activebackground: to set the background color when widget is under the cursor.
    • activeforeground: to set the foreground color when widget is under the cursor.
    • bg: to set the normal background color.
    • command: to call a function.
    • font: to set the font on the button label.
    • image: to set the image on the widget.

      Python

      w = Canvas(master, option=value) master is the parameter used to represent the parent window. 7 w = Canvas(master, option=value) master is the parameter used to represent the parent window. 8 m.mainloop() 0 w = CheckButton(master, option=value) 0 w = CheckButton(master, option=value) 1 m.mainloop() 3 w = CheckButton(master, option=value) 3 w=Label(master, option=value) master is the parameter used to represent the parent window. 8 m.mainloop() 3 w = Listbox(master, option=value) master is the parameter used to represent the parent window. 0 w = Listbox(master, option=value) master is the parameter used to represent the parent window. 1 m.mainloop() 3 w = Listbox(master, option=value) master is the parameter used to represent the parent window. 3 w = Listbox(master, option=value) master is the parameter used to represent the parent window. 4 m.mainloop() 3 w = Listbox(master, option=value) master is the parameter used to represent the parent window. 6 m.mainloop() 3 w = Frame(master, option=value) master is the parameter used to represent the parent window. 8 w = Listbox(master, option=value) master is the parameter used to represent the parent window. 9 m.mainloop() 3 m=tkinter.Tk() where m is the name of the main window object 01 m=tkinter.Tk() where m is the name of the main window object 02 m.mainloop() 3 w = Listbox(master, option=value) master is the parameter used to represent the parent window. 0 w = Listbox(master, option=value) master is the parameter used to represent the parent window. 1 m.mainloop() 3 m=tkinter.Tk() where m is the name of the main window object 07 w = Listbox(master, option=value) master is the parameter used to represent the parent window. 4 m.mainloop() 3 m=tkinter.Tk() where m is the name of the main window object 10 m.mainloop() 3 m=tkinter.Tk() where m is the name of the main window object 12 w = Listbox(master, option=value) master is the parameter used to represent the parent window. 9 m.mainloop() 3 m=tkinter.Tk() where m is the name of the main window object 01 w=Label(master, option=value) master is the parameter used to represent the parent window. 0 Output:
  4. Entry:It is used to input the single line text entry from the user.. For multi-line text input, Text widget is used. The general syntax is:

    w=Entry(master, option=value) master is the parameter used to represent the parent window. There are number of options which are used to change the format of the widget. Number of options can be passed as parameters separated by commas. Some of them are listed below.

    • bd: to set the border width in pixels.
    • bg: to set the normal background color.
    • cursor: to set the cursor used.
    • command: to call a function.
    • highlightcolor: to set the color shown in the focus highlight.
    • width: to set the width of the button.
    • height: to set the height of the button.

      Python

      w = Canvas(master, option=value) master is the parameter used to represent the parent window. 7 w = Canvas(master, option=value) master is the parameter used to represent the parent window. 8 m.mainloop() 0 w = CheckButton(master, option=value) 0 w = CheckButton(master, option=value) 1 m.mainloop() 3 w = CheckButton(master, option=value) 3 m=tkinter.Tk() where m is the name of the main window object 24 m.mainloop() 3 m=tkinter.Tk() where m is the name of the main window object 26 m=tkinter.Tk() where m is the name of the main window object 27 m.mainloop() 3 w = Frame(master, option=value) master is the parameter used to represent the parent window. 8 w=Button(master, option=value) 3 m=tkinter.Tk() where m is the name of the main window object 24 m.mainloop() 3 m=tkinter.Tk() where m is the name of the main window object 33 m=tkinter.Tk() where m is the name of the main window object 27 m.mainloop() 3 m=tkinter.Tk() where m is the name of the main window object 12 w=Button(master, option=value) 3 m=tkinter.Tk() where m is the name of the main window object 38 m.mainloop() 3 m=tkinter.Tk() where m is the name of the main window object 40 m=tkinter.Tk() where m is the name of the main window object 41 m.mainloop() 3 m=tkinter.Tk() where m is the name of the main window object 40 m=tkinter.Tk() where m is the name of the main window object 44 m.mainloop() 3 w = Frame(master, option=value) master is the parameter used to represent the parent window. 8 m=tkinter.Tk() where m is the name of the main window object 47 m.mainloop() 3 m=tkinter.Tk() where m is the name of the main window object 12 w=Button(master, option=value) 3 m=tkinter.Tk() where m is the name of the main window object 51 m.mainloop() 3 m=tkinter.Tk() where m is the name of the main window object 12 m=tkinter.Tk() where m is the name of the main window object 47 m.mainloop() 3 m=tkinter.Tk() where m is the name of the main window object 12 w=Button(master, option=value) 3 w=Label(master, option=value) master is the parameter used to represent the parent window. 0 Output:
  5. Frame: It acts as a container to hold the widgets. It is used for grouping and organizing the widgets. The general syntax is:

    w = Frame(master, option=value) master is the parameter used to represent the parent window. There are number of options which are used to change the format of the widget. Number of options can be passed as parameters separated by commas. Some of them are listed below.

    • highlightcolor: To set the color of the focus highlight when widget has to be focused.
    • bd: to set the border width in pixels.
    • bg: to set the normal background color.
    • cursor: to set the cursor used.
    • width: to set the width of the widget.
    • height: to set the height of the widget.

      Python

      w = Canvas(master, option=value) master is the parameter used to represent the parent window. 7 w = Canvas(master, option=value) master is the parameter used to represent the parent window. 8 m.mainloop() 0 w = CheckButton(master, option=value) 0 m=tkinter.Tk() where m is the name of the main window object 63 m.mainloop() 3 w = CheckButton(master, option=value) 3 m=tkinter.Tk() where m is the name of the main window object 66 m.mainloop() 3 m=tkinter.Tk() where m is the name of the main window object 68 m=tkinter.Tk() where m is the name of the main window object 69 m=tkinter.Tk() where m is the name of the main window object 70 m.mainloop() 3 m=tkinter.Tk() where m is the name of the main window object 68 m=tkinter.Tk() where m is the name of the main window object 73 m.mainloop() 3 m=tkinter.Tk() where m is the name of the main window object 75 m=tkinter.Tk() where m is the name of the main window object 76 m.mainloop() 3 m=tkinter.Tk() where m is the name of the main window object 78 m.mainloop() 3 m=tkinter.Tk() where m is the name of the main window object 80 m=tkinter.Tk() where m is the name of the main window object 81 m.mainloop() 3 m=tkinter.Tk() where m is the name of the main window object 83 w=Button(master, option=value) 3 m=tkinter.Tk() where m is the name of the main window object 85 m.mainloop() 3 m=tkinter.Tk() where m is the name of the main window object 87 m=tkinter.Tk() where m is the name of the main window object 88 m.mainloop() 3 m=tkinter.Tk() where m is the name of the main window object 78 m.mainloop() 3 m=tkinter.Tk() where m is the name of the main window object 92 m=tkinter.Tk() where m is the name of the main window object 93 m.mainloop() 3 m=tkinter.Tk() where m is the name of the main window object 95 w=Button(master, option=value) 3 m=tkinter.Tk() where m is the name of the main window object 97 m.mainloop() 3 m=tkinter.Tk() where m is the name of the main window object 99 m.mainloop() 00 m.mainloop() 3 m=tkinter.Tk() where m is the name of the main window object 78 m.mainloop() 3 m.mainloop() 04 m=tkinter.Tk() where m is the name of the main window object 81 m.mainloop() 3 m.mainloop() 07 w=Button(master, option=value) 3 m.mainloop() 09 m.mainloop() 3 m=tkinter.Tk() where m is the name of the main window object 99 m.mainloop() 12 m.mainloop() 3 m.mainloop() 14 m.mainloop() 3 m.mainloop() 16 m=tkinter.Tk() where m is the name of the main window object 81 m.mainloop() 3 m.mainloop() 19 w=Button(master, option=value) 3 m.mainloop() 21 m.mainloop() 3 m.mainloop() 23 m.mainloop() 24 Output:
  6. Label: It refers to the display box where you can put any text or image which can be updated any time as per the code. The general syntax is:

    w=Label(master, option=value) master is the parameter used to represent the parent window. There are number of options which are used to change the format of the widget. Number of options can be passed as parameters separated by commas. Some of them are listed below.

    • bg: to set the normal background color.
    • bg to set the normal background color.
    • command: to call a function.
    • font: to set the font on the button label.
    • image: to set the image on the button.
    • width: to set the width of the button.
    • height” to set the height of the button.

      Python

      w = Canvas(master, option=value) master is the parameter used to represent the parent window. 7 w = Canvas(master, option=value) master is the parameter used to represent the parent window. 8 m.mainloop() 0 w = CheckButton(master, option=value) 0 m=tkinter.Tk() where m is the name of the main window object 63 m.mainloop() 3 w = CheckButton(master, option=value) 3 w = CheckButton(master, option=value) 4 m.mainloop() 3 m.mainloop() 34 m.mainloop() 3 m.mainloop() 36 w=Button(master, option=value) 3 w=Entry(master, option=value) 3 m.mainloop() 24 Output:
  7. Listbox: It offers a list to the user from which the user can accept any number of options. The general syntax is:

    w = Listbox(master, option=value) master is the parameter used to represent the parent window. There are number of options which are used to change the format of the widget. Number of options can be passed as parameters separated by commas. Some of them are listed below.

    • highlightcolor: To set the color of the focus highlight when widget has to be focused.
    • bg: to set the normal background color.
    • bd: to set the border width in pixels.
    • font: to set the font on the button label.
    • image: to set the image on the widget.
    • width: to set the width of the widget.
    • height: to set the height of the widget.

      Python

      w = Canvas(master, option=value) master is the parameter used to represent the parent window. 7 w = Canvas(master, option=value) master is the parameter used to represent the parent window. 8 m.mainloop() 0 w = CheckButton(master, option=value) 0 m.mainloop() 44 m.mainloop() 3 w = CheckButton(master, option=value) 3 m.mainloop() 47 m.mainloop() 3 m.mainloop() 49 m.mainloop() 50 m=tkinter.Tk() where m is the name of the main window object 12 m.mainloop() 52 m.mainloop() 53 w=Button(master, option=value) 3 m.mainloop() 50 w = Frame(master, option=value) master is the parameter used to represent the parent window. 5 m.mainloop() 52 m.mainloop() 58 w=Button(master, option=value) 3 m.mainloop() 50 m.mainloop() 61 m.mainloop() 52 m.mainloop() 63 w=Button(master, option=value) 3 m.mainloop() 50 m.mainloop() 66 m.mainloop() 52 m.mainloop() 68 w=Button(master, option=value) 3 m.mainloop() 70 m.mainloop() 71 Output:
  8. MenuButton: It is a part of top-down menu which stays on the window all the time. Every menubutton has its own functionality. The general syntax is:

    m=tkinter.Tk() where m is the name of the main window object 0 There are number of options which are used to change the format of the widget. Number of options can be passed as parameters separated by commas. Some of them are listed below.

    • activebackground: To set the background when mouse is over the widget.
    • activeforeground: To set the foreground when mouse is over the widget.
    • bg: to set the normal background color.
    • bd: to set the size of border around the indicator.
    • cursor: To appear the cursor when the mouse over the menubutton.
    • image: to set the image on the widget.
    • width: to set the width of the widget.
    • height: to set the height of the widget.
    • highlightcolor: To set the color of the focus highlight when widget has to be focused.

      Python

      w = Canvas(master, option=value) master is the parameter used to represent the parent window. 7 w = Canvas(master, option=value) master is the parameter used to represent the parent window. 8 m.mainloop() 0 w = CheckButton(master, option=value) 0 m.mainloop() 44 m.mainloop() 3 w = CheckButton(master, option=value) 3 m.mainloop() 79 m.mainloop() 3 m.mainloop() 81 m.mainloop() 3 m.mainloop() 83 m.mainloop() 84 m.mainloop() 85 m.mainloop() 3 m.mainloop() 87 m.mainloop() 3 w = Frame(master, option=value) master is the parameter used to represent the parent window. 8 w=Button(master, option=value) 3 m.mainloop() 91 m.mainloop() 3 m.mainloop() 93 m.mainloop() 94 m.mainloop() 3 w = Listbox(master, option=value) master is the parameter used to represent the parent window. 0 m.mainloop() 97 m.mainloop() 3 w = Listbox(master, option=value) master is the parameter used to represent the parent window. 0 w=Button(master, option=value) 00 m.mainloop() 3 w=Button(master, option=value) 02 w=Button(master, option=value) 03 m.mainloop() 3 w=Button(master, option=value) 05 w=Button(master, option=value) 00 m.mainloop() 3 w=Button(master, option=value) 08 w=Button(master, option=value) 03 m.mainloop() 3 w=Button(master, option=value) 11 w=Button(master, option=value) 12 m.mainloop() 71 Output:
  9. Menu: It is used to create all kinds of menus used by the application. The general syntax is:

    m=tkinter.Tk() where m is the name of the main window object 1 There are number of options which are used to change the format of this widget. Number of options can be passed as parameters separated by commas. Some of them are listed below.

    • title: To set the title of the widget.
    • activebackground: to set the background color when widget is under the cursor.
    • activeforeground: to set the foreground color when widget is under the cursor.
    • bg: to set the normal background color.
    • command: to call a function.
    • font: to set the font on the button label.
    • image: to set the image on the widget.

      Python

      w = Canvas(master, option=value) master is the parameter used to represent the parent window. 7 w = Canvas(master, option=value) master is the parameter used to represent the parent window. 8 m.mainloop() 0 w = CheckButton(master, option=value) 0 m=tkinter.Tk() where m is the name of the main window object 63 m.mainloop() 3 w = CheckButton(master, option=value) 3 w=Button(master, option=value) 21 m.mainloop() 3 w=Button(master, option=value) 23 w=Button(master, option=value) 24 m.mainloop() 3 w=Button(master, option=value) 26 w=Button(master, option=value) 27 m.mainloop() 3 w=Button(master, option=value) 29 w=Button(master, option=value) 30 m.mainloop() 3 w=Button(master, option=value) 32 w=Button(master, option=value) 33 m.mainloop() 3 w=Button(master, option=value) 35 w=Button(master, option=value) 36 m.mainloop() 3 w=Button(master, option=value) 38 w=Button(master, option=value) 3 w=Button(master, option=value) 36 m.mainloop() 3 w=Button(master, option=value) 42 w=Button(master, option=value) 3 w=Button(master, option=value) 44 w=Button(master, option=value) 36 m.mainloop() 3 w=Button(master, option=value) 47 w = Canvas(master, option=value) master is the parameter used to represent the parent window. 2 m.mainloop() 3 w=Button(master, option=value) 50 w=Button(master, option=value) 51 m.mainloop() 3 w=Button(master, option=value) 29 w=Button(master, option=value) 30 m.mainloop() 3 w=Button(master, option=value) 56 w=Button(master, option=value) 33 m.mainloop() 3 w=Button(master, option=value) 59 w=Button(master, option=value) 60 m.mainloop() 3 w=Button(master, option=value) 08 w=Button(master, option=value) 3 w=Label(master, option=value) master is the parameter used to represent the parent window. 0 Output:
  10. Message: It refers to the multi-line and non-editable text. It works same as that of Label. The general syntax is:

    m=tkinter.Tk() where m is the name of the main window object 2 There are number of options which are used to change the format of the widget. Number of options can be passed as parameters separated by commas. Some of them are listed below.

    • bd: to set the border around the indicator.
    • bg: to set the normal background color.
    • font: to set the font on the button label.
    • image: to set the image on the widget.
    • width: to set the width of the widget.
    • height: to set the height of the widget.

      Python

      w = Canvas(master, option=value) master is the parameter used to represent the parent window. 7 w = Canvas(master, option=value) master is the parameter used to represent the parent window. 8 m.mainloop() 0 w = CheckButton(master, option=value) 0 w=Button(master, option=value) 69 m.mainloop() 3 w = CheckButton(master, option=value) 3 w=Button(master, option=value) 72 m.mainloop() 3 w=Button(master, option=value) 74 w=Button(master, option=value) 75 m.mainloop() 3 w=Button(master, option=value) 77 m.mainloop() 3 w=Button(master, option=value) 79 w=Button(master, option=value) 80 m.mainloop() 3 w=Button(master, option=value) 82 w=Button(master, option=value) 3 w=Button(master, option=value) 84 w=Button(master, option=value) 85 Output:
  11. RadioButton: It is used to offer multi-choice option to the user. It offers several options to the user and the user has to choose one option. The general syntax is:

    m=tkinter.Tk() where m is the name of the main window object 3 There are number of options which are used to change the format of this widget. Number of options can be passed as parameters separated by commas. Some of them are listed below.

    • activebackground: to set the background color when widget is under the cursor.
    • activeforeground: to set the foreground color when widget is under the cursor.
    • bg: to set the normal background color.
    • command: to call a function.
    • font: to set the font on the button label.
    • image: to set the image on the widget.
    • width: to set the width of the label in characters.
    • height: to set the height of the label in characters.

      Python

      w = Canvas(master, option=value) master is the parameter used to represent the parent window. 7 w = Canvas(master, option=value) master is the parameter used to represent the parent window. 8 m.mainloop() 0 w = CheckButton(master, option=value) 0 m=tkinter.Tk() where m is the name of the main window object 63 m.mainloop() 3 w = CheckButton(master, option=value) 3 w=Button(master, option=value) 93 m.mainloop() 3 w = Listbox(master, option=value) master is the parameter used to represent the parent window. 0 w=Button(master, option=value) 96 m.mainloop() 3 w=Button(master, option=value) 98 w = Listbox(master, option=value) master is the parameter used to represent the parent window. 4 m.mainloop() 3 w = Canvas(master, option=value) master is the parameter used to represent the parent window. 01 m.mainloop() 3 m=tkinter.Tk() where m is the name of the main window object 12 w = Canvas(master, option=value) master is the parameter used to represent the parent window. 04 m.mainloop() 3 m=tkinter.Tk() where m is the name of the main window object 01 w=Button(master, option=value) 96 m.mainloop() 3 w = Canvas(master, option=value) master is the parameter used to represent the parent window. 09 w = Listbox(master, option=value) master is the parameter used to represent the parent window. 4 m.mainloop() 3 w = Canvas(master, option=value) master is the parameter used to represent the parent window. 01 m.mainloop() 3 w = Frame(master, option=value) master is the parameter used to represent the parent window. 5 w = Canvas(master, option=value) master is the parameter used to represent the parent window. 04 m.mainloop() 3 m=tkinter.Tk() where m is the name of the main window object 01 w=Label(master, option=value) master is the parameter used to represent the parent window. 0 Output:
  12. Scale: It is used to provide a graphical slider that allows to select any value from that scale. The general syntax is:

    m=tkinter.Tk() where m is the name of the main window object 4 There are number of options which are used to change the format of the widget. Number of options can be passed as parameters separated by commas. Some of them are listed below.

    • cursor: To change the cursor pattern when the mouse is over the widget.
    • activebackground: To set the background of the widget when mouse is over the widget.
    • bg: to set the normal background color.
    • orient: Set it to HORIZONTAL or VERTICAL according to the requirement.
    • from_: To set the value of one end of the scale range.
    • to: To set the value of the other end of the scale range.
    • image: to set the image on the widget.
    • width: to set the width of the widget.

      Python

      w = Canvas(master, option=value) master is the parameter used to represent the parent window. 7 w = Canvas(master, option=value) master is the parameter used to represent the parent window. 8 m.mainloop() 0 w = CheckButton(master, option=value) 0 w = CheckButton(master, option=value) 1 m.mainloop() 3 w = CheckButton(master, option=value) 3 w = CheckButton(master, option=value) 4 m.mainloop() 3 w = Canvas(master, option=value) master is the parameter used to represent the parent window. 28 m.mainloop() 3 w = Frame(master, option=value) master is the parameter used to represent the parent window. 8 w = Canvas(master, option=value) master is the parameter used to represent the parent window. 31 m.mainloop() 3 w = Canvas(master, option=value) master is the parameter used to represent the parent window. 33 w=Button(master, option=value) 3 w=Entry(master, option=value) 3 w = CheckButton(master, option=value) 4 m.mainloop() 3 w = Canvas(master, option=value) master is the parameter used to represent the parent window. 28 m.mainloop() 3 w = Frame(master, option=value) master is the parameter used to represent the parent window. 8 w = Canvas(master, option=value) master is the parameter used to represent the parent window. 31 m.mainloop() 3 w=Entry(master, option=value) 9 w = Canvas(master, option=value) master is the parameter used to represent the parent window. 44 m.mainloop() 3 w = Canvas(master, option=value) master is the parameter used to represent the parent window. 46 w=Entry(master, option=value) 3 w=Label(master, option=value) master is the parameter used to represent the parent window. 0 Output:
  13. Scrollbar: It refers to the slide controller which will be used to implement listed widgets. The general syntax is:

    m=tkinter.Tk() where m is the name of the main window object 5 There are number of options which are used to change the format of the widget. Number of options can be passed as parameters separated by commas. Some of them are listed below.

    • width: to set the width of the widget.
    • activebackground: To set the background when mouse is over the widget.
    • bg: to set the normal background color.
    • bd: to set the size of border around the indicator.
    • cursor: To appear the cursor when the mouse over the menubutton.

      Python

      w = Canvas(master, option=value) master is the parameter used to represent the parent window. 7 w = Canvas(master, option=value) master is the parameter used to represent the parent window. 8 m.mainloop() 0 w = CheckButton(master, option=value) 0 m=tkinter.Tk() where m is the name of the main window object 63 m.mainloop() 3 w = CheckButton(master, option=value) 3 w = Canvas(master, option=value) master is the parameter used to represent the parent window. 56 m.mainloop() 3 w = Canvas(master, option=value) master is the parameter used to represent the parent window. 58 w = Canvas(master, option=value) master is the parameter used to represent the parent window. 59 m.mainloop() 3 w = Canvas(master, option=value) master is the parameter used to represent the parent window. 61 m.mainloop() 3 w = Canvas(master, option=value) master is the parameter used to represent the parent window. 63 w = Canvas(master, option=value) master is the parameter used to represent the parent window. 64 m.mainloop() 3 w = Canvas(master, option=value) master is the parameter used to represent the parent window. 66 m.mainloop() 3 w = Canvas(master, option=value) master is the parameter used to represent the parent window. 68 w = Canvas(master, option=value) master is the parameter used to represent the parent window. 69 w=Button(master, option=value) 3 w = Canvas(master, option=value) master is the parameter used to represent the parent window. 71 w = Canvas(master, option=value) master is the parameter used to represent the parent window. 72 w = Canvas(master, option=value) master is the parameter used to represent the parent window. 73 w = Canvas(master, option=value) master is the parameter used to represent the parent window. 74 w = Canvas(master, option=value) master is the parameter used to represent the parent window. 75 w = Canvas(master, option=value) master is the parameter used to represent the parent window. 76 w = Canvas(master, option=value) master is the parameter used to represent the parent window. 77 w = Canvas(master, option=value) master is the parameter used to represent the parent window. 78 w = Canvas(master, option=value) master is the parameter used to represent the parent window. 79 w = Canvas(master, option=value) master is the parameter used to represent the parent window. 80 w = Canvas(master, option=value) master is the parameter used to represent the parent window. 81 w = Canvas(master, option=value) master is the parameter used to represent the parent window. 82 w = Canvas(master, option=value) master is the parameter used to represent the parent window. 83 w = Canvas(master, option=value) master is the parameter used to represent the parent window. 84 m.mainloop() 3 w = Canvas(master, option=value) master is the parameter used to represent the parent window. 86 m.mainloop() 3 w = Canvas(master, option=value) master is the parameter used to represent the parent window. 88 w = Canvas(master, option=value) master is the parameter used to represent the parent window. 89 m.mainloop() 3 w = Canvas(master, option=value) master is the parameter used to represent the parent window. 91 w=Label(master, option=value) master is the parameter used to represent the parent window. 0 Output:
  14. Text: To edit a multi-line text and format the way it has to be displayed. The general syntax is:

    m=tkinter.Tk() where m is the name of the main window object 6 There are number of options which are used to change the format of the text. Number of options can be passed as parameters separated by commas. Some of them are listed below.

    • highlightcolor: To set the color of the focus highlight when widget has to be focused.
    • insertbackground: To set the background of the widget.
    • bg: to set the normal background color.
    • font: to set the font on the button label.
    • image: to set the image on the widget.
    • width: to set the width of the widget.
    • height: to set the height of the widget.

      Python

      w = Canvas(master, option=value) master is the parameter used to represent the parent window. 7 w = Canvas(master, option=value) master is the parameter used to represent the parent window. 8 m.mainloop() 0 w = CheckButton(master, option=value) 0 m=tkinter.Tk() where m is the name of the main window object 63 m.mainloop() 3 w = CheckButton(master, option=value) 3 w = CheckButton(master, option=value) 00 m.mainloop() 3 w = CheckButton(master, option=value) 02 m.mainloop() 3 w = Frame(master, option=value) master is the parameter used to represent the parent window. 5 w=Button(master, option=value) 9 m.mainloop() 3 w = CheckButton(master, option=value) 07 w=Button(master, option=value) 3 w = CheckButton(master, option=value) 09 w = CheckButton(master, option=value) 10 w = CheckButton(master, option=value) 11 w=Button(master, option=value) 3 w=Label(master, option=value) master is the parameter used to represent the parent window. 0 Output:
  15. TopLevel: This widget is directly controlled by the window manager. It don’t need any parent window to work on.The general syntax is:

    m=tkinter.Tk() where m is the name of the main window object 7 There are number of options which are used to change the format of the widget. Number of options can be passed as parameters separated by commas. Some of them are listed below.

    • bg: to set the normal background color.
    • bd: to set the size of border around the indicator.
    • cursor: To appear the cursor when the mouse over the menubutton.
    • width: to set the width of the widget.
    • height: to set the height of the widget.

      Python

      w = Canvas(master, option=value) master is the parameter used to represent the parent window. 7 w = Canvas(master, option=value) master is the parameter used to represent the parent window. 8 m.mainloop() 0 w = CheckButton(master, option=value) 0 m=tkinter.Tk() where m is the name of the main window object 63 m.mainloop() 3 w = CheckButton(master, option=value) 3 w = CheckButton(master, option=value) 21 w=Button(master, option=value) 98 w=Button(master, option=value) 3 m.mainloop() 44 m.mainloop() 3 w = CheckButton(master, option=value) 26 w = CheckButton(master, option=value) 27 m.mainloop() 53 w=Button(master, option=value) 3 m.mainloop() 71 Output:
  16. SpinBox: It is an entry of ‘Entry’ widget. Here, value can be input by selecting a fixed value of numbers.The general syntax is:

    m=tkinter.Tk() where m is the name of the main window object 8 There are number of options which are used to change the format of the widget. Number of options can be passed as parameters separated by commas. Some of them are listed below.

    • bg: to set the normal background color.
    • bd: to set the size of border around the indicator.
    • cursor: To appear the cursor when the mouse over the menubutton.
    • command: To call a function.
    • width: to set the width of the widget.
    • activebackground: To set the background when mouse is over the widget.
    • disabledbackground: To disable the background when mouse is over the widget.
    • from_: To set the value of one end of the range.
    • to: To set the value of the other end of the range.

      Python

      w = Canvas(master, option=value) master is the parameter used to represent the parent window. 7 w = Canvas(master, option=value) master is the parameter used to represent the parent window. 8 m.mainloop() 0 w = CheckButton(master, option=value) 0 w = CheckButton(master, option=value) 1 m.mainloop() 3 w = CheckButton(master, option=value) 3 w = CheckButton(master, option=value) 4 m.mainloop() 3 w = CheckButton(master, option=value) 40 m.mainloop() 3 w = Frame(master, option=value) master is the parameter used to represent the parent window. 8 w = CheckButton(master, option=value) 43 m.mainloop() 3 w = CheckButton(master, option=value) 45 w=Button(master, option=value) 3 w=Entry(master, option=value) 3 w=Label(master, option=value) master is the parameter used to represent the parent window. 0 Output:
  17. PannedWindowIt is a container widget which is used to handle number of panes arranged in it. The general syntax is:

    m=tkinter.Tk() where m is the name of the main window object 9 master is the parameter used to represent the parent window. There are number of options which are used to change the format of the widget. Number of options can be passed as parameters separated by commas. Some of them are listed below.

    • bg: to set the normal background color.
    • bd: to set the size of border around the indicator.
    • cursor: To appear the cursor when the mouse over the menubutton.
    • width: to set the width of the widget.
    • height: to set the height of the widget.

      Python

      w = Canvas(master, option=value) master is the parameter used to represent the parent window. 7 w = Canvas(master, option=value) master is the parameter used to represent the parent window. 8 m.mainloop() 0 w = CheckButton(master, option=value) 0 w = CheckButton(master, option=value) 53 m.mainloop() 3 w = CheckButton(master, option=value) 55 w = CheckButton(master, option=value) 56 m.mainloop() 3 w = CheckButton(master, option=value) 58 m.mainloop() 3 m=tkinter.Tk() where m is the name of the main window object 12 w=Button(master, option=value) 3 w = CheckButton(master, option=value) 62 m.mainloop() 3 w = CheckButton(master, option=value) 64 m.mainloop() 3 w = CheckButton(master, option=value) 66 w=Button(master, option=value) 3 w = CheckButton(master, option=value) 68 w = CheckButton(master, option=value) 69 m.mainloop() 3 w = CheckButton(master, option=value) 71 m.mainloop() 3 w = CheckButton(master, option=value) 73 w = CheckButton(master, option=value) 74 m.mainloop() 44 m.mainloop() 3 w = CheckButton(master, option=value) 77 m.mainloop() 3 w = Canvas(master, option=value) master is the parameter used to represent the parent window. 46 w = CheckButton(master, option=value) 80 w=Label(master, option=value) master is the parameter used to represent the parent window. 0 Output:

If you like GeeksforGeeks and would like to contribute, you can also write an article using

write.geeksforgeeks.org

or mail your article to review-team@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks. Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.

Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Toplist

โพสต์ล่าสุด

แท็ก

แปลภาษาไทย ไทยแปลอังกฤษ แปลภาษาอังกฤษเป็นไทย pantip โปรแกรม-แปล-ภาษา-อังกฤษ พร้อม-คำ-อ่าน อาจารย์ ตจต ศัพท์ทหาร ภาษาอังกฤษ pdf lmyour แปลภาษา ชขภใ ห่อหมกฮวกไปฝากป้าmv กรมพัฒนาฝีมือแรงงาน อบรมฟรี 2566 ขขขขบบบยข ่ส ศัพท์ทางทหาร military words หนังสือราชการ ตัวอย่าง หยน แปลบาลีเป็นไทย ไทยแปลอังกฤษ ประโยค การไฟฟ้านครหลวง การไฟฟ้าส่วนภูมิภาค ข้อสอบโอเน็ต ม.3 ออกเรื่องอะไรบ้าง พจนานุกรมศัพท์ทหาร เมอร์ซี่ อาร์สยาม ล่าสุด แปลภาษามลายู ยาวี Bahasa Thailand กรมพัฒนาฝีมือแรงงาน อบรมออนไลน์ การ์ดจอมือสอง ข้อสอบคณิตศาสตร์ พร้อมเฉลย คะแนน o-net โรงเรียน ค้นหา ประวัติ นามสกุล บทที่ 1 ที่มาและความสําคัญของปัญหา ร. ต จ แบบฝึกหัดเคมี ม.5 พร้อมเฉลย แปลภาษาอาหรับ-ไทย ใบรับรอง กรมพัฒนาฝีมือแรงงาน PEA Life login Terjemahan บบบย มือปราบผีพันธุ์ซาตาน ภาค2 สรุปการบริหารทรัพยากรมนุษย์ pdf สอบโอเน็ต ม.3 จําเป็นไหม เช็คยอดค่าไฟฟ้า แจ้งไฟฟ้าดับ แปลภาษา มาเลเซีย ไทย แผนที่ทวีปอเมริกาเหนือ ่้แปลภาษา Google Translate กระบวนการบริหารทรัพยากรมนุษย์ 8 ขั้นตอน ก่อนจะนิ่งก็ต้องกลิ้งมาก่อน เนื้อเพลง ข้อสอบโอเน็ตม.3 มีกี่ข้อ คะแนนโอเน็ต 65 ตม กรุงเทพ มีที่ไหนบ้าง