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()
相关推荐
bst@微胖子22 分钟前
Python高级语法之selenium
开发语言·python·selenium
查理零世1 小时前
【蓝桥杯集训·每日一题2025】 AcWing 6118. 蛋糕游戏 python
python·算法·蓝桥杯
魔尔助理顾问2 小时前
一个简洁高效的Flask用户管理示例
后端·python·flask
java1234_小锋2 小时前
一周学会Flask3 Python Web开发-request请求对象与url传参
开发语言·python·flask·flask3
诚信爱国敬业友善6 小时前
常见排序方法的总结归类
开发语言·python·算法
架构默片7 小时前
【JAVA工程师从0开始学AI】,第五步:Python类的“七十二变“——当Java的铠甲遇见Python的液态金属
java·开发语言·python
小哥山水之间8 小时前
在 Python 中操作 Excel 文件
开发语言·python·excel
wang_yb9 小时前
『Python底层原理』--CPython的变量实现机制
python·databook
databook9 小时前
『Python底层原理』--CPython的变量实现机制
后端·python
ww1800010 小时前
多目标鲸鱼优化算法-NSWOA-可用于(机器人轨迹跟踪控制/柔性作业车间调度/无人机三维路径规划)
开发语言·python·算法