当前位置:网站首页>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 :
边栏推荐
- No clue about the data analysis report? After reading this introduction of smartbi, you will understand!
- Keep an IT training diary 054- opening and closing
- Code Execution Vulnerability - no alphanumeric rce create_ function()
- Résumé des outils communs et des points techniques de l'examen PMP
- Contest3145 - the 37th game of 2021 freshman individual training match_ 1: Origami
- Global and Chinese market for travel wheelchairs 2022-2028: Research Report on technology, participants, trends, market size and share
- Data collection and summary
- Kiss number + close contact problem
- 中電資訊-信貸業務數字化轉型如何從星空到指尖?
- [untitled] the relationship between the metauniverse and digital collections
猜你喜欢
SQL injection (1) -- determine whether there are SQL injection vulnerabilities
96% of the collected traffic is prevented by bubble mart of cloud hosting
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"
Have you entered the workplace since the first 00???
150 ppt! The most complete "fair perception machine learning and data mining" tutorial, Dr. AIST Toshihiro kamishima, Japan
在尋求人類智能AI的過程中,Meta將賭注押向了自監督學習
AI 助力藝術設計抄襲檢索新突破!劉芳教授團隊論文被多媒體頂級會議ACM MM錄用
Résumé: entropie, énergie libre, symétrie et dynamique dans le cerveau
Node solves cross domain problems
Dans la recherche de l'intelligence humaine ai, Meta a misé sur l'apprentissage auto - supervisé
随机推荐
13. Time conversion function
Keep an IT training diary 055- moral bitch
Bugku Zhi, you have to stop him
3D game modeling is in full swing. Are you still confused about the future?
Global and Chinese market of cell scrapers 2022-2028: Research Report on technology, participants, trends, market size and share
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
[development team follows] API specification
機器學習基礎:用 Lasso 做特征選擇
Record a problem that soft deletion fails due to warehouse level error
Résumé: entropie, énergie libre, symétrie et dynamique dans le cerveau
Setting methods, usage methods and common usage scenarios of environment variables in postman
7 * 24-hour business without interruption! Practice of applying multiple live landing in rookie villages
No clue about the data analysis report? After reading this introduction of smartbi, you will understand!
Unity knapsack system (code to center and exchange items)
What are the conditions for the opening of Tiktok live broadcast preview?
Mysql to PostgreSQL real-time data synchronization practice sharing
Tsinghua University product: penalty gradient norm improves generalization of deep learning model
The 37 year old programmer was laid off, and he didn't find a job for 120 days. He had no choice but to go to a small company. As a result, he was confused
Global and Chinese market for travel wheelchairs 2022-2028: Research Report on technology, participants, trends, market size and share
Unity controls the selection of the previous and next characters