Tkinter learning _ ListBox

Source: Internet
Author: User

# Encoding = utf-8import tkinter as TK # define window = TK. TK () # define the window title window. title ("My window") # define the window size window. geometry ("400x200") # define the label text variable, label_var = TK. stringvar () # define a labalelabel = TK. label (window, BG = "yellow", width = 4, Height = 2, textvar = label_var) # Place the label on the window. pack () def print_selection (): "implementation: When you select the option of the list box and click the button, explicitly select the content to the tag: return: "# Get the selected content value of the List = list_box.get (list_box.curselection () # Set the content to label_var.set (value) in the label text box # define a button, click the button to execute the print_selection function. Button = TK. button (window, text = "", width = 10, Height = 2, command = print_selection) button. pack () # define a text variable list_box_var = TK. stringvar () # set the value of the text variable list_box_var.set (1, 2, 4) # define a list_box = TK. listBox (window, listvar = list_box_var) # a certain list, and insert the list content to the list_items = ["A", "B", "C ", "D"] For item in list_items: list_box.insert ("end", item) # Insert at the end # insert list_box.insert (1, "first") list_box.insert (2, "second") # Delete the list_box.delete (2) list_box.pack () # loop window by index. mainloop ()

Tkinter learning _ ListBox

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.