当前位置:网站首页>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 :
![]()
边栏推荐
- Contest3145 - the 37th game of 2021 freshman individual training match_ 1: Origami
- VRRP+BFD
- This function has none of DETERMINISTIC, NO SQL..... (you *might* want to use the less safe log_bin_t
- 2006 translation
- AI 助力藝術設計抄襲檢索新突破!劉芳教授團隊論文被多媒體頂級會議ACM MM錄用
- A brief talk on professional modeler: the prospect and professional development of 3D game modeling industry in China
- 12. Gettimeofday() and time()
- Dans la recherche de l'intelligence humaine ai, Meta a misé sur l'apprentissage auto - supervisé
- Package and download 10 sets of Apple CMS templates / download the source code of Apple CMS video and film website
- Contest3145 - the 37th game of 2021 freshman individual training match_ G: Score
猜你喜欢

1day vulnerability pushback skills practice (3)

Rhcsa day 3

Johnson–Lindenstrauss Lemma

I stepped on a foundation pit today

Gee import SHP data - crop image

Dare to climb here, you're not far from prison, reptile reverse actual combat case

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

WordPress collection WordPress hang up collection plug-in

Command Execution Vulnerability - command execution - vulnerability sites - code injection - vulnerability exploitation - joint execution - bypass (spaces, keyword filtering, variable bypass) - two ex

WP collection plug-in free WordPress collection hang up plug-in
随机推荐
Advanced learning of MySQL -- Application -- storage engine
1day vulnerability pushback skills practice (3)
機器學習基礎:用 Lasso 做特征選擇
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
Stm32bug [stlink forced update prompt appears in keilmdk, but it cannot be updated]
Have you entered the workplace since the first 00???
PHP database connection succeeded, but data cannot be inserted
Sword finger offer 20 String representing numeric value
[latex] production of complex tables: excel2latex and detail adjustment
Data collection and summary
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
Rhcsa day 2
Www 2022 | taxoenrich: self supervised taxonomy complemented by Structural Semantics
Basé sur... Netcore Development blog Project Starblog - (14) Implementation of theme switching function
Zblog collection plug-in does not need authorization to stay away from the cracked version of zblog
Zhihu million hot discussion: why can we only rely on job hopping for salary increase? Bosses would rather hire outsiders with a high salary than get a raise?
Contest3145 - the 37th game of 2021 freshman individual training match_ E: Eat watermelon
Recent learning fragmentation (14)
[Wu Enda deep learning] beginner learning record 3 (regularization / error reduction)
Problems and solutions of several concurrent scenarios of redis