Python Tkinter –Combobox
combobox = ttk.Combobox(master, option=value, ...)
# python program demonstrating # Combobox widget using tkinter import tkinter as tk from tkinter import ttk # Creating tkinter window window = tk.Tk() window.title('Combobox') window.geometry('500x250') # label text for title ttk.Label(window, text = "GFG Combobox Widget", background = 'green', foreground ="white", font = ("Times New Roman", 15)).grid(row = 0, column = 1) # label ttk.Label(window, text = "Select the Month :", font = ("Times New Roman", 10)).grid(column = 0, row = 5, padx = 10, pady = 25) # Combobox creation n = tk.StringVar() monthchoosen = ttk.Combobox(window, width = 27, textvariable = n) # Adding combobox drop down list monthchoosen['values'] = (' January', ' February', ' March', ' April', ' May', ' June', ' July', ' August', ' September', ' October', ' November', ' December') monthchoosen.grid(column = 1, row = 5) monthchoosen.current() window.mainloop()
import tkinter as tk from tkinter import ttk # Creating tkinter window window = tk.Tk() window.geometry('640x320') # Label ttk.Label(window, text = "Select the Month :", font = ("Times New Roman", 10)).grid(column = 0, row = 15, padx = 10, pady = 25) n = tk.StringVar() monthchoosen = ttk.Combobox(window, width = 27, textvariable = n) # Adding combobox drop down list monthchoosen['values'] = (' January', ' February', ' March', ' April', ' May', ' June', ' July', ' August', ' September', ' October', ' November', ' December') monthchoosen.grid(column = 1, row = 15) # Shows february as a default value monthchoosen.current(1) window.mainloop()
沒有留言:
張貼留言