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()
相关推荐
花酒锄作田2 小时前
使用 pkgutil 实现动态插件系统
python
前端付豪6 小时前
LangChain链 写一篇完美推文?用SequencialChain链接不同的组件
人工智能·python·langchain
曲幽6 小时前
FastAPI实战:打造本地文生图接口,ollama+diffusers让AI绘画更听话
python·fastapi·web·cors·diffusers·lcm·ollama·dreamshaper8·txt2img
老赵全栈实战7 小时前
Pydantic配置管理最佳实践(一)
python
阿尔的代码屋12 小时前
[大模型实战 07] 基于 LlamaIndex ReAct 框架手搓全自动博客监控 Agent
人工智能·python
AI探索者1 天前
LangGraph StateGraph 实战:状态机聊天机器人构建指南
python
AI探索者1 天前
LangGraph 入门:构建带记忆功能的天气查询 Agent
python
FishCoderh1 天前
Python自动化办公实战:批量重命名文件,告别手动操作
python
躺平大鹅1 天前
Python函数入门详解(定义+调用+参数)
python
曲幽1 天前
我用FastAPI接ollama大模型,差点被asyncio整崩溃(附对话窗口实战)
python·fastapi·web·async·httpx·asyncio·ollama