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()
相关推荐
学编程的小虎4 分钟前
用 Python + Vue3 打造超炫酷音乐播放器:网易云歌单爬取 + Three.js 波形可视化
开发语言·javascript·python
yunson_Liu14 分钟前
编写Python脚本在域名过期10天内将域名信息发送到钉钉
开发语言·python·钉钉
布林模型1 小时前
缠论工具czsc快速使用入门(二)
python·缠论·快速入门·czsc
邂逅you1 小时前
用python操作mysql之pymysql库基本操作
数据库·python·mysql
啊森要自信1 小时前
【GUI自动化测试】YAML 配置文件应用:从语法解析到 Python 读写
android·python·缓存·pytest·pip·dash
合作小小程序员小小店2 小时前
web开发,学院培养计划系统,基于Python,FlaskWeb,Mysql数据库
后端·python·mysql·django·web app
渣渣盟2 小时前
解密NLP:从入门到精通
人工智能·python·nlp
老程序员刘飞2 小时前
注册 区块链节点
python
KAIWEILIUCC2 小时前
Python抽象基类(abc.ABC)介绍
python
独行soc2 小时前
2025年渗透测试面试题总结-106(题目+回答)
网络·python·安全·web安全·adb·渗透测试·安全狮