python前端tkinter

基础窗口展示:

python 复制代码
import tkinter as tk

newWin = tk.Tk()
newWin.title("I'm a new window!")
newWin.geometry("400x300+500+300")  #设置窗口的大小以及初始位置

lab = tk.Label(newWin)  #lab = tk.Label()
lab.config(text = "I'm a new label!")   #config可以理解为调整函数
lab.config(fg = "red", bg = "blue") #字体颜色为红色,背景颜色为蓝色
lab.pack()  #将标签组装到窗口上
#bn = tk.Button(newWin, "I'm a new button!")
bn = tk.Button()
bn["text"] = "click"
bn.pack()
entry = tk.Entry(newWin)    #单行输入框
entry.pack()
tk.mainloop()

计算窗口展示:

python 复制代码
from tkinter import *

newWin = Tk()
newWin.title("I'm a computing window!")
newWin.geometry("400x300")
number1 = StringVar()
number2 = StringVar()

lab1 = Label(text = "Num1")
lab1.grid(row = 0, column = 0)
entry1 = Entry(textvariable = number1)
entry1.grid(row = 0, column = 1)

lab2 = Label(text = "Num2")
lab2.grid(row = 1, column = 0)
entry2 = Entry(textvariable = number2)
entry2.grid(row = 1, column = 1)

lab3 = Label(text = "Result")
lab3.grid(row = 2, column = 0)

def computing():
    a = int(number1.get())
    b = int(number2.get())
    lab3.config(text = "Result is " + str(a + b))

bn = Button(text = "Click", command = computing)
#bn["text"] = "click"
bn.grid(row = 2, column = 1)
newWin.mainloop()
相关推荐
Zonda要好好学习4 分钟前
Python入门Day5
python
电商数据girl1 小时前
有哪些常用的自动化工具可以帮助处理电商API接口返回的异常数据?【知识分享】
大数据·分布式·爬虫·python·系统架构
CoooLuckly1 小时前
numpy数据分析知识总结
python·numpy
超龄超能程序猿1 小时前
(六)PS识别:源数据分析- 挖掘图像的 “元语言”技术实现
python·组合模式
amazinging2 小时前
北京-4年功能测试2年空窗-报培训班学测开-第四十四天
python·学习·appium
UrbanJazzerati2 小时前
Xlwings安装报错:Connection timed out & WinError 32?一招解决你的安装难题!
python
Tipriest_2 小时前
Python异常类型介绍
开发语言·python·异常
前端付豪2 小时前
21、用 Python + Pillow 实现「朋友圈海报图生成器」📸(图文合成 + 多模板 + 自动换行)
后端·python
猿榜3 小时前
魔改编译-永久解决selenium痕迹(二)
javascript·python
广东数字化转型3 小时前
java jar 启动应用程序
开发语言·python