In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
Most people do not understand the knowledge points of this article "how to use tkinter and messagebox to write interface and pop-up window in python", so the editor summarizes the following contents, detailed contents, clear steps, and certain reference value. I hope you can get something after reading this article. Let's take a look at this "how to use tkinter and messagebox to write interface and pop-up window in python" article.
1. Grid layout
Description:
Parameter description:
Sticky: allocate extra space in the unit under the normal size of the plug-in (if no attributes are declared, the default plug-in is centered)
NE: upper right
SE: lower right
NW: upper left
N: above
E: on the right
S: below
W: keep to the left
Nails: extend the plug-in vertically and center horizontally
Extension W: extend the plug-in horizontally and center vertically
NumberW: extend the plug-in horizontally and vertically to fill the unit
N+S+W: extend the plug-in vertically and place it on the left
Note: pack () and grid () cannot be used at the same time.
Row: OK
Column: column
2. Button button
Parameter description:
: text: button name
: fg: the foreground color of the button (color of the button text)
: bd: the size of the button border. Default is 2 pixels.
: bg: the background color of the button
: font: text font, font size, font shape. The glyph has overstrike/italic/bold/underline.
: width: the width of the button, if this item is not set, its size to fit the content of the button (the size of the text or picture)
: height: the height of the button, if this item is not set, its size to fit the content of the button (the size of the text or picture)
: image: the picture to be displayed on the button must be assigned to image in the form of a variable. The picture must be in gif format.
: justify: sets the alignment between different lines when displaying multiple lines of text. Options include left, right, and center.
: padx: the padding of the button in the x-axis direction, which refers to the distance between the content of the button and the edge of the button
: pady: the inner margin of the button in the y-axis direction (padding)
: relief: border style, set the control display effect, optional: FLAT, SUNKEN, RAISED, GROOVE, RIDGE.
: wraplength: limit the number of characters displayed on each line of the button. When the number of characters exceeds the limit, the display will wrap.
: underline: underline. The text on the default button is not underlined. The value is the underlined string index. When 0, the first character is underlined, when 1, the second character is underlined, and so on.
: state: button status (status should be in lowercase, uppercase error)
1. Normal is normal
2. Active activation
3. Disabled is disabled
: command: execute the content (the function associated with the button, which is executed when the button is clicked)
: activebackground: the background color of the button when the mouse is held up
: activeforeground: the foreground color of the button when the mouse is held up
3. Use the messagebox of from tkinter import * from tkinter import messagebox # python3.0, which belongs to a component of tkinter top = Tk () #. Generate window top.title ("grid test") # window title top.geometry ('300x400') # Window size def box (): return messagebox.askyesno (title=' pop-up window', message=' content') Popup1 = Button (top, text= "button 1", fg= "blue", bd=2, width=5, command=box, state= "normal") Popup1.grid (row=1, column=1, sticky='E') Popup2 = Button (top, text= "button 2", fg= "yellow", bd=2, width=5, command=box, state= "normal") Popup2.grid (row=2, column=2, sticky='NE')
Effect:
4. The small pop-up window of infinite loop:
Do not choose yes, do not pass!
Here you need to change the source code in messagebox!
1. Enter messagebox and find the method of askyesnocancel pop-up window
2. Modify the judgment to the following content in the method (python will prompt you whether to modify it or not, just agree)
If s = = CANCEL or s = = NO: return None elif s = = YES: return YES
Code:
From tkinter import * from tkinter import messageboxtk = Tk () tk.title ('test') tk.geometry ('100x200') nub = 1def Popup1 (): global nub' askyesnocancel pop-up window: Ask a question; return true if the answer is yes, None if cancelled. '' D = messagebox.askyesnocancel (title=' question', message='python\ nWould you like to keep learning?) While True: if d is None: n = Popup2 (nub) if n is None: pass else: messagebox.showinfo (title=' hint', message=' persistence is victory! \ nCome on! Continue to study together!') # close the pop-up window tk.destroy () return else: return nub + = 1def Popup2 (value): return messagebox.askyesnocancel (title=' selection', message=' the% s'% value) d = Button (tk, text=' start selection', fg='blue', bd=2, width=10, command=Popup1) d.grid (row=1, column=1) Sticky='NE') tk.mainloop () the above is the content of this article on "how to use tkinter and messagebox to write interface and pop-up window in python" I believe we all have a certain understanding. I hope the content shared by the editor will be helpful to you. If you want to know more about the relevant knowledge, please pay attention to the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.