当使用桌面应用程序的时候,
有没有那么一瞬间,
想学习一下桌面应用程序开发?
建议此次课程大家稍作了解不要浪费太多时间,
因为没有哪家公司会招聘以为Python程序员开发桌面程序吧?
开发环境:
- Python 3.6
- Pycharm
代码
界面设置
- 导入模块
import tkinter as tk
- 实例化一个窗体对象
root = tk.Tk()
- 标题
root.title('计算器')
- 大小以及出现的位置
root.geometry("295x280+150+150")
- 透明度
root.attributes("-alpha", 0.9)
- 背景
root["background"] = "#ffffff"
- 标签
lable1 = tk.Label(root, textvariable=result_num, width=20, height=2, font=('宋体', 20), justify='left', background='#ffffff', anchor='se')
- 布局
lable1.grid(padx=4, pady=4, row=0, column=0, columnspan=4)
- 按钮
button_clear = tk.Button(root, text='C', width=5, font=('宋体', 16), relief='flat', background='#C0C0C0', command=lambda: clear())
button_back = tk.Button(root, text='←', width=5, font=('宋体', 16), relief='flat', background='#C0C0C0', command=lambda: back())
button_division = tk.Button(root, text='/', width=5, font=('宋体', 16), relief='flat', background='#C0C0C0', command=lambda: operator('/'))
button_multiplication = tk.Button(root, text='x', width=5, font=(