Python graphical GUI Basic example

Source: Internet
Author: User

"NOTE: The following example Python3 version"

Example one:

Import Tkinter as TK

App = Tk. Tk ()
App.title ("FISHC Demo")

Thelable = Tk. Label (app, text= "My second Window program", width=20,height=10) #标签控件; can display text and bitmaps
Thelable.pack ()

App.mainloop ()

Operation Result:

Example two:

Import Tkinter as TK

Class App: #定义类

def __init__ (self, Master):
frame = tk. Frame (Master) #定义窗体框架
Frame.pack (SIDE=TK. Right, padx=100,pady=100)

#定义按钮
Self.hi_there = Tk. button (frame, text= "Hello", bg= "Red", fg= ' green ', Command=self.say_hi)
Self.hi_there.pack (padx=10, pady=10) #位置


def say_hi (self):
Print ("hi! Hello everyone, finally I met with you. ")


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

Operation Result:

Example Three

From Tkinter Import *

root = Tk ()

Textlabel = Label (root,text= "some distressed, and with joy." She is so simple, not good-looking, but hard to open, \
In order to cater to the breeze swept the heart tenderness, has been trying to open, \ n half a song of the swagger, \
Wanton verdant. And I happened to be passing by. So, the joy of the Love will be born up, with \
The strange warmth and simplicity, \ nthe heart, are dyed wet green, abundant, \ \ Thousands of clues. ", Justify=left, padx=10) #Label Label control; you can display text and bitmaps

Textlabel.pack (Side=left)

Photo = Photoimage (format= "PNG", File=r "C:\Users\Administrator\Desktop\123 (2). png") #PhotoImagecan be used for GIF and PPM/PGM Color bitmaps

Imglabel = Label (root, Image=photo)
Imglabel.pack (Side=right)

Mainloop ()

Operation Result:

Text layout is not what kind, just show the effect, please forgive!

Example Four

From Tkinter Import *

root = Tk ()

Photo = Photoimage (file=r "C:\Users\Administrator\Desktop\123.png")

Thelable = Label (Root,
text= ' Hello ',
Justify = left,
Image=photo,
Compound=center,
Font= ("Blackbody", 20),
FG = "Red")

Thelable.pack ()
Mainloop ()

Operation Result:

Show the effect only!

Example Five

From tkinter Import *

Def callback ():
    var.set (' Blow it, I don't believe it ')
    
root = Tk ()

Frame1 = frame (root) #Frame     frame control; Displays a rectangular area on the screen, used as a container
Frame2 = frame (root)

var = stringvar ()   #设置字符串
Var.set ("The movie you downloaded contains the last adult limit, \ n Please click to watch after 18 years of age)

Textlabel = Label ( Frame1,
                   textvariable = var,
                   justify = left)

Textlabel.pack (side=left)

photo = Photoimage (file=r "C:\Users \administrator\desktop\123 (2). png ")

Imglabel = Label (frame1,text=" Picture One ", Image=photo)
Imglabel.pack (side =right)


Thebutton = button (frame2,text= "I am 18 years of age", Command=callback) #定义一个按钮
Thebutton.pack ()

Frame1.pack (padx=10, pady=10) #定义位置
Frame2.pack (padx=50, pady=50)

Mainloop ()

Run results

Example Six

From Tkinter Import *

root = Tk ()

frame = FRAME (root)

v = Intvar ()

c = Checkbutton (root, text= "test", Variable=v) #定义一个复选框
C.pack ()

L = Label (root, Textvariable=v)
L.pack ()

if __name__ = = ' __main__ ':
Mainloop ()

Operation Result:

Example Seven

Python graphical GUI Basic example

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.