当前位置:网站首页>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 :
![]()
边栏推荐
- (column 23) typical C language problem: find the minimum common multiple and maximum common divisor of two numbers. (two solutions)
- 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
- Examination question bank of constructor decoration direction post skills (constructor) and examination data of constructor decoration direction post skills (constructor) in 2022
- Handler source code analysis
- 基於.NetCore開發博客項目 StarBlog - (14) 實現主題切換功能
- Node write API
- Global and Chinese market of thin film deposition systems 2022-2028: Research Report on technology, participants, trends, market size and share
- The difference between int (1) and int (10)
- Global and Chinese market of digital impression system 2022-2028: Research Report on technology, participants, trends, market size and share
- Code Execution Vulnerability - no alphanumeric rce create_ function()
猜你喜欢

1day vulnerability pushback skills practice (3)

Kiss number + close contact problem
![[Yugong series] February 2022 attack and defense world advanced question misc-84 (MySQL)](/img/4d/4a6b76896bf81a27d036a047f68b2b.jpg)
[Yugong series] February 2022 attack and defense world advanced question misc-84 (MySQL)

What is cloud primordial?

PHP database connection succeeded, but data cannot be inserted

Buuctf QR code

Lichuang EDA learning notes 14: PCB board canvas settings

Have you entered the workplace since the first 00???

I stepped on a foundation pit today

96% of the collected traffic is prevented by bubble mart of cloud hosting
随机推荐
Advanced learning of MySQL -- Application -- storage engine
No clue about the data analysis report? After reading this introduction of smartbi, you will understand!
Global and Chinese market of thin film deposition systems 2022-2028: Research Report on technology, participants, trends, market size and share
Safety tips - seat belt suddenly fails to pull? High speed police remind you how to use safety belts in a standardized way
Stm32bug [stlink forced update prompt appears in keilmdk, but it cannot be updated]
What is the difference between enterprise wechat applet and wechat applet
MySQL data query optimization -- data structure of index
Advanced learning of MySQL -- Application -- index
Crawler practice website image batch download
Buuctf QR code
Unity knapsack system (code to center and exchange items)
Osnabrueck University | overview of specific architectures in the field of reinforcement learning
2022 examination summary of quality controller - Equipment direction - general basis (quality controller) and examination questions and analysis of quality controller - Equipment direction - general b
Examination question bank of constructor decoration direction post skills (constructor) and examination data of constructor decoration direction post skills (constructor) in 2022
System integration meets the three business needs of enterprises
[Wu Enda deep learning] beginner learning record 3 (regularization / error reduction)
Amélioration de l'efficacité de la requête 10 fois! 3 solutions d'optimisation pour résoudre le problème de pagination profonde MySQL
60 year old people buy medical insurance and recommend a better product
Imperial cms7.5 imitation "D9 download station" software application download website source code
2022 attached lifting scaffold worker (special type of construction work) free test questions and attached lifting scaffold worker (special type of construction work) examination papers 2022 attached