【python】GUI筆記

來源:互聯網
上載者:User

標籤:人工   ble   ini   comm   背景   pack   對齊   進階   筆記   

1.Scrapy
dmoz開放式人工目錄。
(1)建立項目:cmd-cd desktop Scrapy startproject pachong
(2)parse接收


2.python如何即時爬取資料


3.easy_GUI太簡單了
GUI的終極選擇:Tkinter


import tkinter as tk

app = tk.TK()
app.title("FishC Dmo")

theLabel = tk.Label(app,text)


4.GUI上課筆記
(1)進階版GUI(把GUI封裝成類)
import tkinter as tk

class APP:
def __init__(self,master):
frame = tk.Frame(master)
frame.pack(side=tk.LEFT,padx=10,pady=10) //設定位置

self.hi_there = tk.Button(frame,text ="打招呼",bg="black",fg="blue",command=self.say_hi)
//fg打招呼字型設定為藍色,bg是背景色的設定,Button是按鈕,command意思是按下按鈕之後的反應
self.hi_there.pack()

def say_hi(self):
print("大家好")

root = tk.Tk()
app = APP(root)

root.mianloop() //到這裡後代碼就不由python負責了,全權交給tkinter
(2)Label和Button組件的講解
from tkinter import * //匯入tkinter模組中的所有東西

root = Tk() //產生一個root視窗

textLabel = Label(rrot,text="您所下載的影片含有未成年人限制內容,\n請滿18周歲再點擊下載!",justify=LEFT,padx=10) //\n是表示換行,justify表示靠左對齊
textLabel.pack(side=LEFT) //視窗布置

phto = PhotoImage(file="18.gif") //傳入圖片儲存路徑
imgLabel = Label(root,image=photo)
imgLabel.pack(side=RIGHT) //設定位置,pack是必須的,GUI到目前為止的設定中,第一步可以設定外來檔案(比如添加圖片一類的,但是不是必須有的),第二部是設定Label屬性,是必須的,第三部是pack,即位置設定,是必須的

mainloop()

(3)Label設定背景彈窗
from tkinter import *

root = Tk()

photo = PhotoImage(file="bg.gif")
theLabel = Label(root,
text="學python\n到FishC",
justify=LEFT,
image=photo,
compound=CENTER,
font=("華康少女字型",20)
fg="white")
theLabel.pack()

mainloop()

(4)button組件講解(可以接收資訊)
有command,按下去就可以調用command後面的方法,可以寫一個函數的名字,然後再def函數。
from tkinter import *

def callback():
ver.set("吹吧你,我猜不信呢")

root =Tk()

frame1 = Frame(root) /兩個架構,上面架構和下面架構放兩個Label,下面放一個Button
frame2 = Frame(root) /這個frame的意思就相當於建立文字框

var = StringVar() //Tkinter的變數,Tkinter裡的字元都要用這個。方便
var.set("您所下載的影片含有未成年人限制的內容,\n請滿18周歲後再點擊觀看!")
textLabel = Label(frame1,
textvariable=var,
justify=LEFT)
textLabel.pack(side=LEFT)

photo = PhotoImage(file="18.gif")
imgLabel = Label(frame1,image=photo)
imgLabel.pack(side=RIGHT)

theButton = Button(frame2,text="我已滿18周歲",command=callback) //精髓在這裡的command
theButton.pack()

frame1.pack(padx=10,pady=10)
frame2,pack(padx=10,pady=10)

mainloop()

(5)翻拍程式
from tkinter import *

root = Tk()

GIRLS = ["西施","貂蟬","王昭君","楊玉環"]

v = []

for girl in GIRLS:
v.append(IntVar())
b = Checkbuttoon(root,text=girl,variable=v[-1])
b.pack()

mainloop()

(6)列表按鈕

【python】GUI筆記

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.