python 开发窗体应用程序,python 窗口程序开发

大家好,小编为大家解答python 开发窗体应用程序的问题。很多人还不知道python 窗口程序开发,现在让我们一起来看看吧!

一、创建Window窗口

# 创建Window窗口.py
import tkinter

root=tkinter.Tk()   # 创建Window窗口对象
# 窗口属性
root.geometry('300x200+300+300')    # 窗口的宽度x高度

root.title('我的第一个GUI程序')    # 设置窗口标题

root.config(bg='#fffc11')   # 窗口背景颜色

label=tkinter.Label(root,text='hello,python')

label.pack()

button1=tkinter.Button(root,text='BUTTON1')

button1.pack(side=tkinter.LEFT)

button2=tkinter.Button(root,text='BUTTON2')

button2.pack(side=tkinter.RIGHT)
# 显示窗口(消息循环)
root.mainloop()    

二、创建登录窗口

代码如下:

from tkinter import *

root =Tk()
root.title('登录')
root.geometry('400x200')
root.config(bg='#ffcc00')

Label(root,text='用户名',width=6).place(x=1,y=1)
Entry(root,width=20).place(x=45,y=1)
Label(root,text='密码',width=6).place(x=1,y=20)
Entry(root,width=20,show='*').place(x=45,y=20)
Button(root,text='登录',width=8).place(x=40,y=40)
Button(root,text='取消',width=8).place(x=110,y=40)

root.mainloop()

 三、创建计算器窗口

# grid布局.py

from tkinter import *

root = Tk()
root.title('计算器示例')
root.geometry('300x150+280+280')
root.config(bg='#cc66ff')

L1 = Button(root,text='1',width=5,bg='yellow')
L2 = Button(root,text='2',width=5,bg='blue')
L3 = Button(root,text='3',width=5,bg='red')
L4 = Button(root,text='4',width=5,bg='green')
L5 = Button(root,text='5',width=5,bg='orange')
L6 = Button(root,text='6',width=5,bg='cyan')
L7 = Button(root,text='7',width=5,bg='purple')
L8 = Button(root,text='8',width=5,bg='pink')
L9 = Button(root,text='9',width=5,bg='red')
L0 = Button(root,text='0',width=5,bg='yellow')
Lp = Button(root,text='.',bg='pink')

L1.grid(row=0,column=0)
L2.grid(row=0,column=1)
L3.grid(row=0,column=2)
L4.grid(row=1,column=0)
L5.grid(row=1,column=1)
L6.grid(row=1,column=2)
L7.grid(row=2,column=0)
L8.grid(row=2,column=1)
L9.grid(row=2,column=2)
L0.grid(row=3,column=0,columnspan=2,sticky=E+W)
Lp.grid(row=3,column=2,sticky=E+W)

root.mainloop()

  • 6
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值