用 Python 打造你的遊戲
2020
小草、RexWu
ctl12345
終於看得到惹
import tkinter as tk
window = tk.Tk()
msg = tk.Label(master=window, text="你好!")
msg.pack()
window.mainloop()
import tkinter as tk
window = tk.Tk()
window.geometry("500x500")
msg = tk.Label(master=window, text="你好!")
msg.pack()
window.mainloop()
import tkinter as tk
window = tk.Tk()
window.geometry("500x500")
msg = tk.Label(master=window, text="你好!")
msg.pack()
window.mainloop()
import tkinter as tk
window = tk.Tk()
def clk():
print("尼亂按 ><")
btn = tk.Button(master=window, text="按我!", command=clk)
msg.pack()
window.mainloop()
import tkinter as tk
window = tk.Tk()
def clk():
btn["text"] = "不要亂按 ><"
btn = tk.Button(master=window, text="按我!", command=clk)
btn.pack()
window.mainloop()
import tkinter as tk
window = tk.Tk()
window.geometry("300x300")
label0 = tk.Label(text="我在最上面!")
label0.pack(side = tk.TOP)
label3 = tk.Label(text="我在左邊 ( ~'ω')~ ")
label3.pack(side = tk.LEFT)
label4 = tk.Label(text=" ~('ω'~ ) 窩在右邊")
label4.pack(side = tk.RIGHT)
window.mainloop()
import tkinter as tk
window = tk.Tk()
window.geometry("500x500")
frame = tk.Frame()
frame.grid(row=0, column=0)
label = tk.Label(master=frame, text="左上角")
label.pack()
frame = tk.Frame()
frame.grid(row=1, column=1)
label = tk.Label(master=frame, text="右下角")
label.pack()
window.mainloop()
import tkinter as tk
window = tk.Tk()
window.geometry("500x500")
def clk():
print("不要亂按><")
for i in range(3):
for j in range(3):
frame = tk.Frame()
frame.grid(row=i, column=j)
btn = tk.Button(master=frame, text=str(i) + str(j), width=5, command=clk)
btn.pack()
window.mainloop()
from tkinter import *
from tkinter.font import Font
window = Tk()
textLabel = Label(window,
font = Font(size = 80),
text = '我是變大的字串')
textLabel.pack()
mainloop()
from tkinter import *
from tkinter.font import Font
window = Tk()
textLabel = Label(window,
font = Font(size = 80),
bg = 'blue',
fg = 'red',
text = '我是變大的字串')
textLabel.pack()
mainloop()
Label.pack() #自動配置
Label.place(x = 100, y = 150) #精確一些的配置
Label.grid(column = 0, row = 0) #好用又不麻煩
StringVar() #字串
IntVar() #整數
DoubleVar() #浮點數
BooleanVar() #布林值
num = IntVar() #建立變數
num.set(10) #設定變數的值
i = num.get() #取得變數的值
print(i)
num.set(100)
print(num.get())
from tkinter import *
window = Tk()
inputNum = Entry(window)
def iuput():
newNum = inputNum.get()
print(newNum)
inputBtn = Button(window, text = "輸入", command = iuput)
inputNum.pack()
inputBtn.pack()
mainloop()