tkinter 输入输出窗口

比较详细具体的教程:

Python tkinter教程-04:输入框_罗富茗的博客-CSDN博客_python tkinter 输入框

字体设置:

tkinter模块字体(font)的使用 | Python笔记

import tkinter as tk
import tkinter.font as tkFont
root = tk.Tk()  # must be here
f1 = tkFont.Font(family='microsoft yahei', size=16, weight='bold')
f2 = tkFont.Font(family='times', size=20, slant='italic')
f3 = tkFont.Font(family='Helvetica', size=24, underline=1, overstrike=1)
tk.Label(root, text='tkFont', font=f1).pack()
tk.Label(root, text='tkFont', font=f2).pack()
tk.Label(root, text='tkFont', font=f3).pack()
tk.Label(root, text='default font').pack()
print(tkFont.families())
root.mainloop()

窗口大小及位置设置:

Python tkinter(笔记)设置Tk窗口放置在屏幕中央_ZQHCSD的博客-CSDN博客

两个输入框,输入符合要求的值后点击按键退出


#以上均为教程。以下要输入层数
import tkinter as tk
import tkinter.font as tkFont
from tkinter import StringVar
import time
window = tk.Tk()
#字体设置,注意中文字体需为ubunt支持的中文字体,具体可由tkFont.families()输出查看
f1 = tkFont.Font(family='song ti', size=20, weight='bold')
f2 = tkFont.Font(family='song ti', size=16, weight='bold')
f3 = tkFont.Font(family='gothic', size=16)
f4 = tkFont.Font(family='song ti', size=16)

#窗口大小
width = 500
heigh = 200
#获取屏幕尺寸
screenwidth = window.winfo_screenwidth()
screenheight = window.winfo_screenheight()

window.title("dicom裁剪范围")
window.geometry('%dx%d+%d+%d'%(width, heigh, (screenwidth-width)/2, (screenheight-heigh)/2))

l0 = tk.Label(window, text="请设置需裁剪的dicom切片范围(至少包含48张切片)",font=f1)
l0.pack()

l1 = tk.Label(window, text="起始裁剪层数:",font=f2)
l1.pack()

e1 = tk.Entry(window, font=f3)
e1.pack()

l2 = tk.Label(window, text="结束裁剪层数:", font=f2)
l2.pack()

e2 = tk.Entry(window, font=f3)
e2.pack()

# def get():
#     print("将裁剪以下切片:",e1.get(),":",e2.get())
    
# b = tk.Button(window, text="完成设置!", font=f2, command=get)
# b.pack()
    
def ending():
    global start_slice,end_slice,text
    start_slice=e1.get()
    end_slice=e2.get()
    text = StringVar()
#     print(start_slice,end_slice)
#     print(type(start_slice))
#     print(type(end_slice))    
    try:
        start_slice = int(start_slice.strip())
        end_slice = int(end_slice.strip())
#         print(start_slice,end_slice)
#         print(type(start_slice))
#         print(type(end_slice))
        if (end_slice-start_slice)<48 or(start_slice<0):#关于end_slice超出上限的部分在后面代码强制限定
            text.set("输入错误,请重新输入!")
            err = tk.Label(window, textvariable=text, font=f4, fg="red")
            err.pack()
        else:
            text.set("设置成功!")    
            err = tk.Label(window, textvariable=text, font=f4, fg="red")
            err.pack()
            time.sleep(3)
            window.destroy()
    except:
        text.set("输入错误,请重新输入!")         
        err = tk.Label(window, textvariable=text, font=f4, fg="red")
        err.pack() 
# tk.Button(window,text='退出',width=15, pady=5, command=ending).place(x=300, y=150, anchor='nw')
tk.Button(window,text='完成',width=15, pady=5, command=ending).pack(side='right')
window.mainloop()
print(start_slice,end_slice)

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值