当前位置:网站首页>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 :
![]()
边栏推荐
- Sword finger offer 14- I. cut rope
- CSCI 2134
- 1day vulnerability pushback skills practice (3)
- @Scheduled scheduled tasks
- Ai aide à la recherche de plagiat dans le design artistique! L'équipe du professeur Liu Fang a été embauchée par ACM mm, une conférence multimédia de haut niveau.
- Contest3145 - the 37th game of 2021 freshman individual training match_ F: Smallest ball
- 查詢效率提昇10倍!3種優化方案,幫你解决MySQL深分頁問題
- Rhcsa day 3
- Rhcsa day 2
- The difference between MCU serial communication and parallel communication and the understanding of UART
猜你喜欢

Li Chuang EDA learning notes IX: layers

Bugku Zhi, you have to stop him

C learning notes: C foundation - Language & characteristics interpretation
![[Valentine's Day confession code] - Valentine's Day is approaching, and more than 10 romantic love effects are given to the one you love](/img/ab/066923f1aa1e8dd8dcc572cb60a25d.jpg)
[Valentine's Day confession code] - Valentine's Day is approaching, and more than 10 romantic love effects are given to the one you love

Hospital network planning and design document based on GLBP protocol + application form + task statement + opening report + interim examination + literature review + PPT + weekly progress + network to

7 * 24-hour business without interruption! Practice of applying multiple live landing in rookie villages

Unity knapsack system (code to center and exchange items)

No clue about the data analysis report? After reading this introduction of smartbi, you will understand!

Advanced learning of MySQL -- Application -- index

Dare to climb here, you're not far from prison, reptile reverse actual combat case
随机推荐
Have you entered the workplace since the first 00???
Unity controls the selection of the previous and next characters
[Yugong series] February 2022 attack and defense world advanced question misc-83 (QR easy)
Sword finger offer 20 String representing numeric value
Create real-time video chat in unity3d
Sword finger offer 14- I. cut rope
Latex tips slash \backslash
The difference between int (1) and int (10)
Global and Chinese market of handheld melanoma scanners 2022-2028: Research Report on technology, participants, trends, market size and share
Contest3145 - the 37th game of 2021 freshman individual training match_ D: Ranking
Advanced learning of MySQL -- Application -- index
17. File i/o buffer
I stepped on a foundation pit today
What are the conditions for the opening of Tiktok live broadcast preview?
Sword finger offer:55 - I. depth of binary tree
AI 助力藝術設計抄襲檢索新突破!劉芳教授團隊論文被多媒體頂級會議ACM MM錄用
16. System and process information
PMP 考試常見工具與技術點總結
Libcblas appears when installing opencv import CV2 so. 3:cannot open shared object file:NO such file or directory
14. Process time