"Python" GUI notes

Source: Internet
Author: User
Tags set background

1.Scrapy
DMOZ Open Manual directory.
(1) Create project: CMD-CD Desktop Scrapy startproject pachong
(2) Parse receive


2.python How to crawl data in real time


3.easy_gui is so easy.
GUI's ultimate choice: Tkinter


Import Tkinter as TK

App = tk.tk ()
App.title ("FISHC Dmo")

Thelabel = Tk. Label (App,text)


4.GUI Lesson Notes
(1) Advanced GUI (package GUI into Class)
Import Tkinter as TK

Class APP:
def __init__ (Self,master):
frame = tk. Frame (Master)
Frame.pack (SIDE=TK. LEFT,PADX=10,PADY=10)//Set Location

Self.hi_there = Tk. button (Frame,text = "Hello", bg= "Black", fg= "Blue", Command=self.say_hi)
FG Greeting font is set to blue, BG is the setting of background color, button is buttons, command means reaction after pressing button
Self.hi_there.pack ()

def say_hi (self):
Print ("Good for Everyone")

root = Tk. Tk ()
App = app (root)

Root.mianloop ()///After the code is not in the hands of Python, the full authority to Tkinter
(2) Explanation of label and button components
From tkinter Import *//import everything in the Tkinter module

root = Tk ()//Generate a root window

Textlabel = Label (rrot,text= "The movie you downloaded contains restricted content for minors, \ n Please be 18 years old and click to download!", justify=left,padx=10)//\n is a newline, justify means left-aligned
Textlabel.pack (side=left)//Window layout

Phto = Photoimage (file= "18.gif")//Incoming Picture storage path
Imglabel = Label (Root,image=photo)
Imglabel.pack (Side=right)//Set location, pack is required, GUI so far settings, the first step can set foreign files (such as adding a picture class, but is not necessary), the second is to set the Label property, is necessary, The third part is the pack, which is the location setting, is required

Mainloop ()

(3) Label set background pop-up window
From Tkinter Import *

root = Tk ()

Photo = Photoimage (file= "Bg.gif")
Thelabel = Label (Root,
text= "Learning python\n to FISHC",
Justify=left,
Image=photo,
Compound=center,
Font= ("Hua Kang Girl Font", 20)
fg= "White")
Thelabel.pack ()

Mainloop ()

(4) button component Explanation (can receive information)
command, you can call the command following the method, you can write a function name, and then the DEF function.
From Tkinter Import *

DEF callback ():
Ver.set ("Blow you, I guess not to believe it")

Root =TK ()

Frame1 = FRAME (root)/two frames, with two labels on the frame above and below, with a button below
Frame2 = FRAME (root)/This frame is equivalent to creating a text box

var = stringvar ()//tkinter variable, which is used in Tkinter characters. Convenient
Var.set ("The movie you downloaded contains restricted content for minors, \ n Please click to watch when you are 18 years old!") ")
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= "I am 18 years old", command=callback)//The Essence of command here
Thebutton.pack ()

Frame1.pack (padx=10,pady=10)
Frame2,pack (padx=10,pady=10)

Mainloop ()

(5) Remake procedure
From Tkinter Import *

root = Tk ()

GIRLS = ["Xi Shi", "Marten Cicada", "Wang Zhaojun", "Yang Yuhuan"]

v = []

For girl in GIRLS:
V.append (Intvar ())
b = Checkbuttoon (Root,text=girl,variable=v[-1])
B.pack ()

Mainloop ()

(6) List button

"Python" GUI notes

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.