日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 >

学习笔记(49):Python实战编程-place布局

發(fā)布時(shí)間:2023/12/10 46 豆豆
生活随笔 收集整理的這篇文章主要介紹了 学习笔记(49):Python实战编程-place布局 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

立即學(xué)習(xí):https://edu.csdn.net/course/play/19711/343111?utm_source=blogtoedu

1.place布局:

1)最靈活的布局方式,是根據(jù)坐標(biāo)點(diǎn)來進(jìn)行組件的位置布局的

2)確定坐標(biāo)點(diǎn)后,組件從坐標(biāo)點(diǎn)開始展開,即以指定坐標(biāo)點(diǎn)為組件的左上定位點(diǎn)

3)組件.place(x=,y=)

?

2. place直接布局

image_label_1 = tkinter.Label(root,image = image) image_label_2 = tkinter.Label(root,image = image)image_label_1.place(x = 50,y = 50) image_label_2.place(x= 100,y = 100)

?

import tkinter#導(dǎo)入創(chuàng)建窗體的相關(guān)模塊 import osimage_path = r'C:\Users\jinlin\Desktop\python_further_study\GUI編程\resources' + os.sep + 'linlianqin.gif'#因?yàn)槊總€(gè)平臺(tái)的分隔符不一樣,所以用os.sep可以自動(dòng)切換到相應(yīng)平臺(tái)的分隔符class Mainwindow():#創(chuàng)建窗口類def __init__(self):root = tkinter.Tk()#創(chuàng)建主體窗口root.title('linlianqin')#定義窗體的名字root.geometry('500x500')#定義窗體的初始大小root.maxsize(1200,1200)#設(shè)置窗口可以顯示的最大尺寸#----------------------對(duì)組件進(jìn)行place布局-------------------------image = tkinter.PhotoImage(file = image_path)image_label_1 = tkinter.Label(root,image = image)image_label_2 = tkinter.Label(root,image = image)image_label_1.place(x = 50,y = 50)image_label_2.place(x= 100,y = 100)root.mainloop()#顯示窗口,這個(gè)代碼一定要放在所有窗口設(shè)置的后面if __name__ == '__main__':Mainwindow()#將窗體類實(shí)例化

?

3. place布局加組件拖拽事件,一般有拖拽事件的都是使用place布局的

self.image_label_1.place(x=0,y=0)self.image_label_2.place(x=50,y=50)self.image_label_1.bind("<B1-Motion>",self.label_move_1)self.image_label_2.bind("<B1-Motion>",self.label_move_2)self.root.mainloop() # 顯示窗口,這個(gè)代碼一定要放在所有窗口設(shè)置的后面#定義組件拖拽功能 def label_move_1(self,event):self.image_label_1.place(x=event.x,y = event.y)#event事件中含有下x,y坐標(biāo)點(diǎn)的信息def label_move_2(self,event):self.image_label_2.place(x=event.x,y = event.y) import tkinter#導(dǎo)入創(chuàng)建窗體的相關(guān)模塊 import osimage_path = r'C:\Users\jinlin\Desktop\python_further_study\GUI編程\resources' + os.sep + 'linlianqin.gif'#因?yàn)槊總€(gè)平臺(tái)的分隔符不一樣,所以用os.sep可以自動(dòng)切換到相應(yīng)平臺(tái)的分隔符class Mainwindow():#創(chuàng)建窗口類def __init__(self):self.root = tkinter.Tk()#創(chuàng)建主體窗口self.root.title('linlianqin')#定義窗體的名字self.root.geometry('500x500')#定義窗體的初始大小self.root.maxsize(1200,1200)#設(shè)置窗口可以顯示的最大尺寸#----------------------對(duì)組件進(jìn)行place布局-------------------------self.image = tkinter.PhotoImage(file = image_path)self.image_label_1 = tkinter.Label(self.root,image = self.image)self.image_label_2 = tkinter.Label(self.root,image = self.image)self.image_label_1.place(x=0,y=0)self.image_label_2.place(x=50,y=50)self.image_label_1.bind("<B1-Motion>",self.label_move_1)self.image_label_2.bind("<B1-Motion>",self.label_move_2)self.root.mainloop() # 顯示窗口,這個(gè)代碼一定要放在所有窗口設(shè)置的后面#定義組件拖拽功能def label_move_1(self,event):self.image_label_1.place(x=event.x,y = event.y)#event事件中含有下x,y坐標(biāo)點(diǎn)的信息def label_move_2(self,event):self.image_label_2.place(x=event.x,y = event.y)if __name__ == '__main__':Mainwindow()#將窗體類實(shí)例化

?

總結(jié)

以上是生活随笔為你收集整理的学习笔记(49):Python实战编程-place布局的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。