網站首頁 編程語言 正文
1、grid 布局
說明:
參數說明:
- ? ?
sticky
:在插件正常尺寸下,分配單元中多余的空間(如果沒有聲明屬性,默認插件居中) - ? ? ? ?
NE
:靠右上方 - ? ? ? ?
SE
:靠右下方 - ? ? ? ?
NW
:靠左上方 - ? ? ? ?
N
:靠上方 - ? ? ? ?
E
:靠右方 - ? ? ? ?
S
:靠下方 - ? ? ? ?
W
:靠左方 - ? ? ? ?
N+S
:在垂直方向上延伸插件,并保持水平居中 - ? ? ????
E+W
:在水平方向上延伸插件,并保持垂直居中 - ? ? ? ?
N+W
:在水平和垂直方向上延伸插件,填滿單位 - ? ? ? ?
N+S+W
:在垂直方向上延伸插件,并靠左布放
注意:pack() 和 ?grid() 是不能同時使用的?
- ? ?
row
: 行 - ? ?
column
:列
2、Button 按鈕
參數說明:
- ? ? :text:按鈕名稱
- ? ? :fg:按鈕的前景色(按鈕文本的顏色)
- ? ? :bd:按鈕邊框的大小,默認為 2 個像素
- ? ? :bg: 按鈕的背景色
- ? ? :font: 文本字體,文字字號,文字字形。字形有overstrike/italic/bold/underline
- ? ? :width:按鈕的寬度,如未設置此項,其大小以適應按鈕的內容(文本或圖片的大小)
- ? ? :height: 按鈕的高度,如未設置此項,其大小以適應按鈕的內容(文本或圖片的大小)
- ? ? :image: 按鈕上要顯示的圖片,圖片必須以變量的形式賦值給image,圖片必須是gif格式
- ? ? :justify: 顯示多行文本的時候,設置不同行之間的對齊方式,可選項包括left, right, center
- ? ? :padx: 按鈕在x軸方向上的內邊距(padding),是指按鈕的內容與按鈕邊緣的距離
- ? ? :pady: 按鈕在y軸方向上的內邊距(padding)
- ? ? :relief: 邊框樣式,設置控件顯示效果,可選的有:FLAT、SUNKEN、RAISED、GROOVE、RIDGE。
- ? ? :wraplength: 限制按鈕每行顯示的字符的數量,超出限制數量后則換行顯示
- ? ? :underline: 下劃線。默認按鈕上的文本都不帶下劃線。取值就是帶下劃線的字符串索引,為 0 時,第一個字符帶下劃線,為 1 時,第兩個字符帶下劃線,以此類推
- ? ? :state:按鈕狀態 (狀態要用小寫,大寫報錯)
- ? ? ? ? 1、normal ?正常
- ? ? ? ? 2、active ?激活
- ? ? ? ? 3、disabled ?禁用
- ? ? :command:執行內容(按鈕關聯的函數,當按鈕被點擊時,執行該函數)
- ? ? :activebackground: 當鼠標放上去時,按鈕的背景色
- ? ? :activeforeground: 當鼠標放上去時,按鈕的前景色
3、使用:
from tkinter import * from tkinter import messagebox ?# python3.0的messagebox,屬于tkinter的一個組件 top = Tk() ?#。生成窗口 top.title("grid test") ?# ?窗口標題 top.geometry('300x400') ?#。窗口大小 def box(): ? ? return messagebox.askyesno(title='彈窗', message='內容') Popup1 = Button(top, text="按鈕1", fg="blue", bd=2, width=5, command=box, state="normal") Popup1.grid(row=1, column=1, sticky='E') Popup2 = Button(top, text="按鈕2", fg="yellow", bd=2, width=5, command=box, state="normal") Popup2.grid(row=2, column=2, sticky='NE')
效果:
4、無限循環的小彈窗:
:不選yes,不給通過!
這里需要改一下messagebox
內的源代碼!
- 1、進入
messagebox
內,找到askyesnocancel
彈窗方法 - 2、在方法內把判斷修改為一下內容(python會提示是否修改,同意即可)
? ? if s == CANCEL or s == NO: ? ? ? ? return None ? ? elif s == YES: ? ? ? ? return YES
代碼:
from tkinter import * from tkinter import messagebox tk = Tk() tk.title('測試') tk.geometry('100x200') nub = 1 def Popup1(): ? ? global nub ? ? ''' ? ? askyesnocancel 彈窗: ?方法解釋是這樣的 ? ? Ask a question; return true if the answer is yes, None if cancelled. ? ? ''' ? ? d = messagebox.askyesnocancel(title='問題', message='python \n你是否愿意繼續學習下去?') ? ? while True: ? ? ? ? if d is None: ? ? ? ? ? ? n = Popup2(nub) ? ? ? ? ? ? if n is None: ? ? ? ? ? ? ? ? pass ? ? ? ? ? ? else: ? ? ? ? ? ? ? ? messagebox.showinfo(title=' 提示 ', message='堅持就是勝利!\n加油!一起繼續學習下去!') ? ? ? ? ? ? ? ? # ?關閉彈窗 ? ? ? ? ? ? ? ? tk.destroy() ? ? ? ? ? ? ? ? return ? ? ? ? else: ? ? ? ? ? ? return ? ? ? ? nub += 1 def Popup2(value): ? ? return messagebox.askyesnocancel(title='選擇', message='你選擇的第%s次' % value) d = Button(tk, text='開始選擇', fg='blue', bd=2, width=10, command=Popup1) d.grid(row=1, column=1, sticky='NE') tk.mainloop()
原文鏈接:https://blog.csdn.net/weixin_44750991/article/details/120294614
相關推薦
- 2023-04-08 C#獲取時間戳的方法及時間戳轉換問題_C#教程
- 2022-06-17 Android?SearchView搜索控件使用方法詳解_Android
- 2022-06-02 Nginx虛擬主機的配置步驟過程全解_nginx
- 2022-04-01 kubelet請求觸發流控,導致節點NotReady
- 2023-07-07 spring security權限路由匹配restful格式的詳情id設計
- 2022-06-21 Android實現登錄注冊功能_Android
- 2022-07-26 在Pycharm set ops_config=local之后,直接echo %ops_config
- 2023-04-11 Python單個項目列表轉換為整數的實現_python
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支