Tkinter

Tkinter为Python的内置包
基本属性:
参照下面代码,基本可以完成需求

from tkinter import *
from tkinter import messagebox
from tkinter import simpledialog
from tkinter import filedialog

def ui_process():
    root =Tk()
    root.geometry("300x400+500+500")

#标签   
    L_titile = Label(root,text='半知君',)
    L_titile.config(font='Helvetica -15 bold',fg='blue')
    L_titile.place(x=150,y=20,anchor="center")
    L_author = Label(root, text='作者:LCC')
    L_author.config(font='Helvetica -10 bold')
    L_author.place(x=250,y=380)

#按钮
    B_0 = Button(root, text="对话框", command=CreatDialog)
    B_0.place(x=90,y=200)
    B_1 = Button(root, text="确定", command=print)
    B_1.place(x=150, y=200)
    B_OK = Button(root,text="创建",command=lambda:button_process(root))
    B_OK.place(x=200,y=200)
    B_NO = Button(root, text="取消")
    B_NO.place(x=250,y=200)

#单选按钮
    v = IntVar()
    R_ONE=Radiobutton(root, text="One", variable=v, value=1,command=lambda:Print_b(1)).place(x=60,y=150)
    R_TWO=Radiobutton(root, text="Two", variable=v, value=2,command=lambda:Print_b(2)).place(x=10,y=150)

#滑块
    W = Scale(root, from_=0, to=100,orient=HORIZONTAL)#orient=HORIZONTAL 横向,默认纵向
    W.place(x=50,y=300)
    # print(W.get())  #获取滑块值

#菜单栏
    menubar = Menu(root)
    filemenu = Menu(menubar, tearoff=0)
    filemenu.add_command(label="Open", command=OpenFile)
    filemenu.add_command(label="Save", command=SaveFile)
    # filemenu.add_separator()#分割线
    filemenu.add_command(label="Exit", command=root.quit)
    menubar.add_cascade(label="File", menu=filemenu)
    root.config(menu=menubar)

    mainloop()

#按钮对应函数入口
def button_process(root):
    #创建消息框
    messagebox.askokcancel('Python Tkinter', '确认创建窗口?')
    messagebox.askquestion('Python Tkinter', "确认创建窗口?")
    messagebox.askyesno('Python Tkinter', '是否创建窗口?')
    messagebox.showerror('Python Tkinter', '未知错误')
    messagebox.showinfo('Python Tkinter', 'hello world')
    messagebox.showwarning('Python Tkinter', '电脑即将爆炸,请迅速离开')
    root1 = Toplevel(root)

def PrintHello():
    print("hello")

def Print_b(a):
    print(a)

#创建对话框
def CreatDialog():
    world = simpledialog.askstring('Python Tkinter', 'Input String', initialvalue = 'Python Tkinter')
    print(world)
    # simpledialog.askinteger()
    # simpledialog.askfloat()

#文件操作的对话框
def OpenFile():
    f = filedialog.askopenfilename(title='打开文件', filetypes=[('Python', '*.py *.pyw'), ('All Files', '*')])
    print(f)
    #可使用os 模块运行文件
def SaveFile():
    f = filedialog.asksaveasfilename(title='保存文件', initialdir='d:\mywork', initialfile='hello.py')
    print(f)
    #可调用OS模块保存
if __name__ == "__main__":
    print("开始")
    ui_process()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值