Python中Tk模块简单窗口设计

Python中Tk和PyQt都可以设计小程序,区别在于:Tk界面美观度相对较差,但由于是Python的内置模块,最终生成的程序大小相比于PyQt较小。

import tkinter  # 导入TKinter模块
from tkinter import StringVar
from tkinter import *

from PIL import ImageTk, Image
ytm = tkinter.Tk()  # 创建Tk对象
ytm.title("test_tool")  # 设置窗口标题
ytm.geometry("400x300")  # 设置窗口尺寸
canvas = tkinter.Canvas(ytm, width=400, height=400, bd=0, highlightthickness=0)

imgpath = './p1.jpg'
img = Image.open(imgpath)
photo = ImageTk.PhotoImage(img)

canvas.create_image(200, 150, image=photo)
canvas.pack()
#entry = tkinter.Entry(ytm, insertbackground='red', highlightthickness=2)
#entry.pack()
ytm.resizable(False,False)#不允许改变窗口大小
l1 = tkinter.Label(ytm, text="")# 标签
l1.place(x=40,y=20)
#l1.pack()  # 指定包管理器放置组件
user_text1 = tkinter.Entry()  # 创建文本框
user_text1.place(x=80,y=20)
l2 = tkinter.Label(ytm, text="")  # 标签
#l2.pack()
l2.place(x=40,y=60)
user_text2 = tkinter.Entry()  # 创建文本框
#user_text2.pack()
user_text2.place(x=80,y=60)
l3 = tkinter.Label(ytm, text="")  # 标签
#l3.pack()
l3.place(x=40,y=100)
user_text3 = tkinter.Entry()  # 创建文本框
user_text3.place(x=80,y=100)
l4 = tkinter.Label(ytm, text="")  # 标签
l4.place(x=40,y=140)
filename=StringVar()
filename02=StringVar()
filename03=StringVar()
user_text4 = tkinter.Entry(ytm, textvariable = filename)  # 创建文本框
user_text4.place(x=80,y=140)
l5 = tkinter.Label(ytm, text="")  # 标签
l5.place(x=40,y=180)
user_text5= tkinter.Entry(ytm, textvariable = filename02)  # 创建文本框
user_text5.place(x=80,y=180)
l6 = tkinter.Label(ytm, text="")  # 标签
l6.place(x=40,y=220)
user_text6 = tkinter.Entry(ytm, textvariable = filename03)  # 创建文本框
user_text6.place(x=80,y=220)
ytm.mainloop()

效果图:

 

posted @ 2019-03-16 16:28  autotest_man  阅读(3592)  评论(0编辑  收藏  举报