当前位置:网站首页>GUI Graphical user interface programming (XIV) optionmenu - what do you want your girlfriend to wear on Valentine's day
GUI Graphical user interface programming (XIV) optionmenu - what do you want your girlfriend to wear on Valentine's day
2022-07-04 03:06:00 【Progress Xiaobai】
Thank you for opening Xiaobai's article
“ I hope you have made a little progress today , One step closer to a better life !”
Catalog
Write it at the front
Used in the eighth phase Checkbutton The check button has been used to select the page , Today, let's use a new component .
OptionMenu( Menu selection ) In fact, it is the revision of the pull-down menu , Its invention makes up for Listbox The component cannot realize the regret of the drop-down list box .
Creating a selection menu is very simple , Only need it Tkinter Variable ( Used to record what the user selected ) And several options :
The most basic example
from tkinter import *
root = Tk()
variable = StringVar()
variable.set("one")
w = OptionMenu(root,variable,"one","two","three")
w.pack()
mainloop()
Application process
1. If you want to create option menu, We need to use OptionMenu Class and pass a variable and a series of option values to the constructor .
from Tkinter import *
master = Tk()
variable = StringVar(master)
variable.set("one") # default value
w = OptionMenu(master, variable, "one", "two", "three")
w.pack()
mainloop()
single click one Or the one on the right button, A selection list will pop up , Inside, we passed it to OptionMenu List of options , After we choose any one of them ,button The characters on the left will also change .
2. To get the selected option value , We can use variable get Method .
from Tkinter import *
master = Tk()
var = StringVar(master)
var.set("one") # initial value
option = OptionMenu(master, var, "one", "two", "three", "four")
option.pack()
#
# test stuff
def ok():
print "value is", var.get()
master.quit()
button = Button(master, text="OK", command=ok)
button.pack()
mainloop()
Application example
from tkinter import *
root = Tk(); root.geometry("300x200")
v = StringVar(root)
v.set(" What do you want your girlfriend to wear most ?")
om = OptionMenu(root, v, " Black silk ", " White silk ", " maid ")
om["width"] = 15
om.pack()
def test1():
print(" Favorite type :", v.get())
Button(root, text=" determine ", command=test1).pack()
root.mainloop()
Running results :
Background display :
边栏推荐
- Base d'apprentissage de la machine: sélection de fonctionnalités avec lasso
- Crawler practice website image batch download
- 2022 registration examination for safety production management personnel of fireworks and firecracker production units and examination skills for safety production management personnel of fireworks an
- Problems and solutions of several concurrent scenarios of redis
- 7 * 24-hour business without interruption! Practice of applying multiple live landing in rookie villages
- 7 * 24-hour business without interruption! Practice of applying multiple live landing in rookie villages
- Imperial cms7.5 imitation "D9 download station" software application download website source code
- Buuctf QR code
- Zblog collection plug-in does not need authorization to stay away from the cracked version of zblog
- Unspeakable Prometheus monitoring practice
猜你喜欢
In my spare time, I like to write some technical blogs and read some useless books. If you want to read more of my original articles, you can follow my personal wechat official account up technology c
C # learning notes: structure of CS documents
96% of the collected traffic is prevented by bubble mart of cloud hosting
(column 23) typical C language problem: find the minimum common multiple and maximum common divisor of two numbers. (two solutions)
SQL injection (1) -- determine whether there are SQL injection vulnerabilities
Record a problem that soft deletion fails due to warehouse level error
[latex] production of complex tables: excel2latex and detail adjustment
Measurement fitting based on Halcon learning [4] measure_ arc. Hdev routine
Problems and solutions of several concurrent scenarios of redis
MySQL data query optimization -- data structure of index
随机推荐
Unity writes a character controller. The mouse controls the screen to shake and the mouse controls the shooting
Teach you how to optimize SQL
Is online futures account opening safe and reliable? Which domestic futures company is better?
Pagoda SSL can't be accessed? 443 port occupied? resolvent
2022 examination summary of quality controller - Equipment direction - general basis (quality controller) and examination questions and analysis of quality controller - Equipment direction - general b
Format character%* s
Jenkins continuous integration environment construction V (Jenkins common construction triggers)
2022 Guangxi provincial safety officer a certificate examination materials and Guangxi provincial safety officer a certificate simulation test questions
Imperial cms7.5 imitation "D9 download station" software application download website source code
Keepalived set the master not to recapture the VIP after fault recovery (it is invalid to solve nopreempt)
AI 助力藝術設計抄襲檢索新突破!劉芳教授團隊論文被多媒體頂級會議ACM MM錄用
Global and Chinese market of handheld melanoma scanners 2022-2028: Research Report on technology, participants, trends, market size and share
[software implementation series] software implementation interview questions with SQL joint query diagram
FRP intranet penetration
The first spring of the new year | a full set of property management application templates are presented, and Bi construction is "out of the box"
Measurement fitting based on Halcon learning [4] measure_ arc. Hdev routine
[Yugong series] February 2022 attack and defense world advanced question misc-84 (MySQL)
Gee import SHP data - crop image
No clue about the data analysis report? After reading this introduction of smartbi, you will understand!
Site favorites