日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python 如何删除frame 中的 label标签控件_玩转图形界面编程—解析Python小挑战No12(2)...

發布時間:2025/3/19 python 17 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python 如何删除frame 中的 label标签控件_玩转图形界面编程—解析Python小挑战No12(2)... 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

《Python真好玩,教孩子學編程》小挑戰【轉載】

第十二章,玩轉圖形界面編程書籍《Python真好玩,教孩子學編程》

講解了如何通過tkinter模塊來完成圖形交互界面

tkinter小挑戰(二)

(1)使用grid布局管理方式布局一個計算器。

from tkinter import Tk from tkinter import Frame from tkinter import Label from tkinter import Buttonroot = Tk() root.geometry('310x400') root.title("計算器")#定義最上面的空白面板 frame_show = Frame(width=300,height = 5) frame_show.pack()#定義顯示字符串的標簽,anchor設置控件的錨點(東南西北) show_label = Label(frame_show, text = "0",width=300, height=3,font=("黑體", 16, "bold"),anchor='e') show_label.pack(padx=10, pady=1)#定義按鈕區 frame_button = Frame(width=300,height = 180) frame_button.pack(padx=5, pady=1) #第一行 b_1 = Button(frame_button, text="MC", width=6, height=3).grid(row=0, column=0) b_2 = Button(frame_button, text="MR", width=6, height=3).grid(row=0, column=1) b_3 = Button(frame_button, text="MS", width=6, height=3).grid(row=0, column=2) b_4 = Button(frame_button, text="M+", width=6, height=3).grid(row=0, column=3) b_5 = Button(frame_button, text="M-", width=6, height=3).grid(row=0, column=4) #第二行 b_6 = Button(frame_button, text="←", width=6, height=3).grid(row=1, column=0) b_7 = Button(frame_button, text="CE", width=6, height=3).grid(row=1, column=1) b_8 = Button(frame_button, text="C", width=6, height=3).grid(row=1, column=2) b_9 = Button(frame_button, text="±", width=6, height=3).grid(row=1, column=3) b_10 = Button(frame_button, text="√", width=6, height=3).grid(row=1, column=4)#第三行 b_11 = Button(frame_button, text="7", width=6, height=3).grid(row=2, column=0) b_12 = Button(frame_button, text="8", width=6, height=3).grid(row=2, column=1) b_13 = Button(frame_button, text="9", width=6, height=3).grid(row=2, column=2) b_14 = Button(frame_button, text="/", width=6, height=3).grid(row=2, column=3) b_15 = Button(frame_button, text="%", width=6, height=3).grid(row=2, column=4) #第4行 b_16 = Button(frame_button, text="4", width=6, height=3).grid(row=3, column=0) b_17 = Button(frame_button, text="5", width=6, height=3).grid(row=3, column=1) b_18 = Button(frame_button, text="6", width=6, height=3).grid(row=3, column=2) b_19 = Button(frame_button, text="*", width=6, height=3).grid(row=3, column=3) b_20 = Button(frame_button, text="1/x", width=6, height=3).grid(row=3, column=4) #第5行 b_21 = Button(frame_button, text="1", width=6, height=3).grid(row=4, column=0) b_22 = Button(frame_button, text="2", width=6, height=3).grid(row=4, column=1) b_23 = Button(frame_button, text="3", width=6, height=3).grid(row=4, column=2) b_24 = Button(frame_button, text="-", width=6, height=3).grid(row=4, column=3) b_25 = Button(frame_button, text="=", width=6, height=6).grid(row=4, column=4,rowspan=2) #第6行 b_26 = Button(frame_button, text="0", width=13, height=3).grid(row=5, column=0,columnspan = 2) b_27 = Button(frame_button, text=".", width=6, height=3).grid(row=5, column=2) b_28 = Button(frame_button, text="+", width=6, height=3).grid(row=5, column=3)root.mainloop()

運行程序,結果為:

windows系統的效果

mac系統的效果

解析:

程序中,使用了pack和grid兩種布局管理方式,

pack:指定相對位置的布局方式,不要求精準布局的時候,可以選擇使用。

grid:按照行和列的方式來排列組件。組件的位置由行號和列號指定。

使用了3種控件:

1. Label組件:展示文字

2. Button組件:按鈕組件

3. Frame組件:這是一個框架組件,用來在屏幕上顯示一個矩形區域,多作為容器來布局窗體。

程序中,把計算器劃分了兩個矩形區域,分別是:

frame_show:頭部的空白區域。

frame_button:按鈕區域。

接下來看下具體的代碼:

from tkinter import Tk from tkinter import Frame from tkinter import Label from tkinter import Button

導入tkinter模塊中需要使用的函數和組件

root = Tk()

創建根窗口

root.geometry('310x400')

設置窗口大小為:310x400,這里的x就是小寫英文字母x

root.title("計算器")

設置窗口標題為"計算器"

#定義最上面的空白面板 frame_show = Frame(width=300,height = 5) frame_show.pack()

通過Frame組件劃分了最上面的空白面板,設置width=300,height = 5

#定義顯示字符串的標簽,anchor設置控件的錨點(東南西北) show_label = Label(frame_show, text = "0",width=300, height=3,font=("黑體", 16, "bold"),anchor='e') show_label.pack(padx=10, pady=1)

創建了標簽組件,在窗口中展示。設置的屬性有:

text:設置標簽組件展示的文字是0。

width:設置標簽組件的長為300。

height:設置標簽組件的寬為3。

font :設置文字的字體為黑體,大小為16并且加粗。

anchor:設置文字的位置在標簽的東的方向。

padx:設置標簽組件的水平方向的外邊距。

pady:設置標簽組件的垂直方向的外邊距。

#定義按鈕區 frame_button = Frame(width=300,height = 180) frame_button.pack(padx=5, pady=1)

通過Frame組件劃分了按鈕區域,設置width=300,height = 180

#第一行 b_1 = Button(frame_button, text="MC", width=6, height=3).grid(row=0, column=0) b_2 = Button(frame_button, text="MR", width=6, height=3).grid(row=0, column=1) b_3 = Button(frame_button, text="MS", width=6, height=3).grid(row=0, column=2) b_4 = Button(frame_button, text="M+", width=6, height=3).grid(row=0, column=3) b_5 = Button(frame_button, text="M-", width=6, height=3).grid(row=0, column=4) #第二行 b_6 = Button(frame_button, text="←", width=6, height=3).grid(row=1, column=0) b_7 = Button(frame_button, text="CE", width=6, height=3).grid(row=1, column=1) b_8 = Button(frame_button, text="C", width=6, height=3).grid(row=1, column=2) b_9 = Button(frame_button, text="±", width=6, height=3).grid(row=1, column=3) b_10 = Button(frame_button, text="√", width=6, height=3).grid(row=1, column=4)#第三行 b_11 = Button(frame_button, text="7", width=6, height=3).grid(row=2, column=0) b_12 = Button(frame_button, text="8", width=6, height=3).grid(row=2, column=1) b_13 = Button(frame_button, text="9", width=6, height=3).grid(row=2, column=2) b_14 = Button(frame_button, text="/", width=6, height=3).grid(row=2, column=3) b_15 = Button(frame_button, text="%", width=6, height=3).grid(row=2, column=4) #第4行 b_16 = Button(frame_button, text="4", width=6, height=3).grid(row=3, column=0) b_17 = Button(frame_button, text="5", width=6, height=3).grid(row=3, column=1) b_18 = Button(frame_button, text="6", width=6, height=3).grid(row=3, column=2) b_19 = Button(frame_button, text="*", width=6, height=3).grid(row=3, column=3) b_20 = Button(frame_button, text="1/x", width=6, height=3).grid(row=3, column=4) #第5行 b_21 = Button(frame_button, text="1", width=6, height=3).grid(row=4, column=0) b_22 = Button(frame_button, text="2", width=6, height=3).grid(row=4, column=1) b_23 = Button(frame_button, text="3", width=6, height=3).grid(row=4, column=2) b_24 = Button(frame_button, text="-", width=6, height=3).grid(row=4, column=3) b_25 = Button(frame_button, text="=", width=6, height=6).grid(row=4, column=4,rowspan=2) #第6行 b_26 = Button(frame_button, text="0", width=13, height=3).grid(row=5, column=0,columnspan = 2) b_27 = Button(frame_button, text=".", width=6, height=3).grid(row=5, column=2) b_28 = Button(frame_button, text="+", width=6, height=3).grid(row=5, column=3)

通過grid布局管理方式布局計算器的各種按鈕。

使用到的屬性有:

row:行號

column:列號

rowspan:行跨度,多用來合并一列中的多個單元。

columnspan:列跨度,多用來合并一行中的多個單元。

root.mainloop()

讓根窗口持續展示。

意外收獲:

使用mac系統和windows運行同一段代碼的時候,發現一樣的代碼,效果居然不一樣。

在mac系統上運行正常,但是windows系統中會很丑。

所以當在windows運行的時候,

把b_25的height改成5,其他所有Button組件的height改成2,會獲得更好的效果,文章開頭的效果圖就是調整之后的效果。

代碼為:

from tkinter import Tk from tkinter import Frame from tkinter import StringVar from tkinter import Label from tkinter import Buttonroot = Tk() root.geometry('310x400') root.title("計算器")#定義最上面的空白面板 frame_show = Frame(width=300,height=10) frame_show.pack()#定義顯示字符串的標簽,anchor設置控件的錨點(東南西北) show_label = Label(frame_show, text = "0",width=300, height=3,font=("黑體", 16, "bold"),anchor='e') show_label.pack(padx=10, pady=1)#定義按鈕區 frame_button = Frame(width=300,height=180) frame_button.pack(padx=5, pady=1) #第一行 b_1 = Button(frame_button, text="MC", width=6, height=2).grid(row=0, column=0) b_2 = Button(frame_button, text="MR", width=6, height=2).grid(row=0, column=1) b_3 = Button(frame_button, text="MS", width=6, height=2).grid(row=0, column=2) b_4 = Button(frame_button, text="M+", width=6, height=2).grid(row=0, column=3) b_5 = Button(frame_button, text="M-", width=6, height=2).grid(row=0, column=4) #第二行 b_6 = Button(frame_button, text="←", width=6, height=2).grid(row=1, column=0) b_7 = Button(frame_button, text="CE", width=6, height=2).grid(row=1, column=1) b_8 = Button(frame_button, text="C", width=6, height=2).grid(row=1, column=2) b_9 = Button(frame_button, text="±", width=6, height=2).grid(row=1, column=3) b_10 = Button(frame_button, text="√", width=6, height=2).grid(row=1, column=4)#第三行 b_11 = Button(frame_button, text="7", width=6, height=2).grid(row=2, column=0) b_12 = Button(frame_button, text="8", width=6, height=2).grid(row=2, column=1) b_13 = Button(frame_button, text="9", width=6, height=2).grid(row=2, column=2) b_14 = Button(frame_button, text="/", width=6, height=2).grid(row=2, column=3) b_15 = Button(frame_button, text="%", width=6, height=2).grid(row=2, column=4) #第4行 b_16 = Button(frame_button, text="4", width=6, height=2).grid(row=3, column=0) b_17 = Button(frame_button, text="5", width=6, height=2).grid(row=3, column=1) b_18 = Button(frame_button, text="6", width=6, height=2).grid(row=3, column=2) b_19 = Button(frame_button, text="*", width=6, height=2).grid(row=3, column=3) b_20 = Button(frame_button, text="1/x", width=6, height=2).grid(row=3, column=4) #第5行 b_21 = Button(frame_button, text="1", width=6, height=2).grid(row=4, column=0) b_22 = Button(frame_button, text="2", width=6, height=2).grid(row=4, column=1) b_23 = Button(frame_button, text="3", width=6, height=2).grid(row=4, column=2) b_24 = Button(frame_button, text="-", width=6, height=2).grid(row=4, column=3) b_25 = Button(frame_button, text="=", width=6, height=5).grid(row=4, column=4,rowspan=2) #第6行 b_26 = Button(frame_button, text="0", width=13, height=2).grid(row=5, column=0,columnspan = 2) b_27 = Button(frame_button, text=".", width=6, height=2).grid(row=5, column=2) b_28 = Button(frame_button, text="+", width=6, height=2).grid(row=5, column=3)root.mainloop()

您的鼓勵是我最大的動力

總結

以上是生活随笔為你收集整理的python 如何删除frame 中的 label标签控件_玩转图形界面编程—解析Python小挑战No12(2)...的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 欧美一级一区二区 | 久久久久成人网 | 成人精品视频一区二区 | 成人高潮片免费视频 | 日本v片| 亚洲AV成人精品 | 九九热视频在线免费观看 | 日韩精品中文字幕一区 | 日色网站 | 美女18网站 | 黄色一级视频免费观看 | 丁香九月激情 | 91操人 | 手机看片1024在线 | 免费一级全黄少妇性色生活片 | 国产三级做爰高清在线 | www.色日本| 免费观看毛片网站 | 狠狠躁18三区二区一区视频 | 综合五月婷婷 | 成人黄色国产 | 精品久久久久一区二区国产 | 日本成人在线一区 | 日韩黄色一级片 | 欧美特黄一级视频 | 国产精品久久av无码一区二区 | 超碰2022| 午夜免费在线观看 | 免费黄色小说视频 | 免费成人进口网站 | 欧美亚洲图片小说 | 亚洲淫片| 人人爽视频 | 熟妇高潮一区二区高潮 | 一区二区三区四区人妻 | 麻豆视频国产 | 好吊色免费视频 | 熊猫电影yy8y全部免费观看 | 麻豆蜜臀 | 欧美色国 | 日本色中色 | 四虎成人精品在永久免费 | 丰满女人又爽又紧又丰满 | 校园激情av | 国产成人毛毛毛片 | 精品无码一区二区三区的天堂 | 国产草逼视频 | 欧美11p| 午夜精品久久久久久久99热黄桃 | 另类小说一区二区 | 91色区| 三级小视频在线观看 | 91精品黄色 | 日韩av一区二区在线播放 | 中文写幕一区二区三区免费观成熟 | 国产一区二区波多野结衣 | mm1313亚洲国产精品美女 | 日韩视频成人 | 日韩专区在线 | 巨茎人妖videos另类 | 青青草原伊人 | 亚洲国产一区在线观看 | 日本免费专区 | 一级性生活免费视频 | 欧美成人片在线观看 | 国产拍拍视频 | 人妻巨大乳一二三区 | 亚洲精品无码久久久 | 韩国bj大尺度vip福利网站 | 欧美亚洲中文精品字幕 | 黄页网站免费观看 | 久久久久中文字幕亚洲精品 | 超碰在线cao | av天天在线| 97成人超碰| 日韩精品成人在线观看 | 蜜桃精品在线观看 | 青草青在线视频 | 日本青青草视频 | 成人激情视频网站 | 国产精品第72页 | 黄色大片在线 | 日韩一级在线 | 久久久88| 国产一区精品在线 | 黄色小视频在线观看 | 国产在线视频一区 | 亚洲人免费 | xx色综合| 涩涩在线看 | 女人高潮被爽到呻吟在线观看 | 成人黄色一级视频 | 很黄很色的视频 | 午夜爱爱免费视频 | 少妇av一区 | 亚洲女成人图区 | 亚洲小视频在线观看 | 欧美中文字幕第一页 | 娇小萝被两个黑人用半米长 |