Python tkinter入門demo

功能實現:

主要是使用了tkinter庫中的Tk,Frame,Label, Button,place函數實現了一個窗口上有兩個button。

之後詳細介紹!

import tkinter as tk
# mytk = tk.Toplevel()
mytk = tk.Tk()
mytk.title('tk_demo')
mytk.geometry("1000x1000")

frame = tk.Frame(mytk, bg="yellow")
frame.pack()

tip_text = "hello!"
tip_label = tk.Label(frame, text=tip_text, width=324, height=300)
tip_label.pack()

def ok_callback():
    print('提示','你點擊了確定按鈕!')
    # tk.messagebox.showinfo('提示','你點擊了確定按鈕!')

def cancal_callback():
    print('提示','你點擊了取消按鈕!')
    # tk.messagebox.showinfo('提示','你點擊了取消按鈕!')
    

ok_btn = tk.Button(frame,text="確定", bg="red", fg="yellow", activebackground="#fdfdbc", bd=0, cursor="hand2", command=ok_callback, width=30, height=42)
# ok_btn.pack()
ok_btn.place(relx=0.2, rely=0.1)    

cancel_btn = tk.Button(frame, text="取消",bg="red",fg="yellow", activebackground="#fdfdbc",  bd=0, cursor="hand2",command=cancal_callback, width=30, height=42)
# cancel_btn.pack()
cancel_btn.place(relx=0.535, rely=0.1)

mytk.mainloop()

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章