- python GUI tkinter
from tkinter import *
from tkinter.ttk import *
# writing code needs to
# create the main window of
# the application creating
# main window object named root
root = Tk()
# giving title to the main window
root.title("First_Program")
# Label is what output will be
# show on the window
label = Label(root, text ="Hello World !").pack()
# calling mainloop method which is used
# when your application is ready to run
# and it tells the code to keep displaying
root.mainloop()
- 加入botton : hello
from tkinter import *
# create root window
root = Tk()
# frame inside root window
frame = Frame(root)
# geometry method
frame.pack()
# giving title to the main window
root.title("First_Program")
# button inside frame which is
# inside root
button = Button(frame, text ='hello')
button.pack()
# Tkinter event loop
root.mainloop()
- button 用法
# python 自带tkinter
from tkinter import *
# 初始化Tk()
root = Tk()
# botton的frame
frame = Frame(root)
frame.pack()
# 加入button
button = Button(frame, text = 'hello')
button.pack()
# loop gui
root.mainloop()