爱code的小白 2023-09-22 20:36 采纳率: 33.3%
浏览 7
已结题

tkinter的entry的值为什么显示不了?

各位帮帮忙吧,为什么显示不了项目名称?

from tkinter import *   #导入tkinter库
from tkinter import messagebox as ms
import time as t    #导入time库

def new_prog():     #定义‘新建项目’函数
    global dstr
    window2 = Toplevel()
    window2.geometry('210x100+320+100')
    window2.attributes("-topmost", True)    #位于最上层
    window2.resizable(height=False, width=False)    #大小不可调
    window2.title('选项')     #设置标题

    dstr = StringVar()
    
    Label(window2, text='项目名称', width=6).place(x=18, y=5)
    Entry(window2, width=10, textvariable=dstr).place(x=5, y=25)
    
    def click_yes():
        window2.destroy()
        label1 = Label(window, text=dstr, width=8,font=('kaiti', 18, 'bold'))
        label1.place(x=100, y=90)
        #window.update()
    def click_no():     #定义‘取消’按钮函数
        window2.destroy()

    Label(window2, text='小时', width=6).place(x=100, y=5)
    Spinbox(window2, from_=0, to=23, width=5, wrap=True).place(x=100, y=25)

    Label(window2, text='分钟', width=6).place(x=150, y=5)
    Spinbox(window2, from_=0, to=59, width=5, wrap=True).place(x=150, y=25)

    Button(window2, text='确定', width=6, command=click_yes).place(x=50, y=70)

    Button(window2, text='取消', width=6, command=click_no).place(x=110, y=70)
    
    window2.mainloop
    return

def config():
    def clickyes():
        window3.destroy()

    def clickno():
        window3.destroy()

    def a1():
        window.attributes("-alpha", 0.2)

    def a2():
        window.attributes("-alpha", 0.4)

    def a3():
        window.attributes("-alpha", 0.5)

    def a4():
        window.attributes("-alpha", 0.6)

    def a5():
        window.attributes("-alpha", 0.8)

    def a6():
        window.attributes("-alpha", 1)

    window3 = Tk()
    window3.geometry('310x200+320+50')
    window3.title('设置')
    window3.attributes("-topmost", True)
    window3.resizable(height=False, width=False)

    Label(window3, text='透明度(%)', width=10).place(x=5, y=5)

    Radiobutton(window3, text='20%', value=0, command=a1).place(x=0, y=30)
    Radiobutton(window3, text='40%', value=1, command=a2).place(x=50, y=30)
    Radiobutton(window3, text='50%', value=2, command=a3).place(x=100, y=30)
    Radiobutton(window3, text='60%', value=3, command=a4).place(x=150, y=30)
    Radiobutton(window3, text='80%', value=4, command=a5).place(x=200, y=30)
    Radiobutton(window3, text='100%', value=5, command=a6).place(x=250, y=30)

    Button(window3, text='确定', width=8, command=clickyes).place(x=80, y=170)
    Button(window3, text='取消', width=8, command=clickno).place(x=155, y=170)

    window3.mainloop


window = Tk()
window.geometry('300x300+0+0')
window.title('时间管理器')
window.attributes("-alpha", 1)
window.attributes("-topmost", True)
window.resizable(height=False, width=False)

Button(window, text='新建项目', width=10, command=new_prog).place(x=0, y=50)
Button(window, text='设置', width=10, command=config).place(x=220, y=50)
Label(window,text='当前任务:',width=8,font=('kaiti', 16, 'bold')).place(x=0,y=90)

label2=Label(window,text=t.strftime('%H:%M:%S',t.localtime(t.time())),font=('huawenxihei', 28, 'bold'))
label2.pack(anchor=N)
def trickit():
    currentTime=t.strftime('%H:%M:%S',t.localtime(t.time()))
    label2.config(text=currentTime)
    window.update()
    label2.after(1000, trickit)
label2.after(1000, trickit)
    
window.mainloop()

  • 写回答

2条回答 默认 最新

  • LiliONENZEZF 2023-09-22 21:46
    关注

    第20行代码label1 = Label(window, text=dstr, width=8,font=('kaiti', 18, 'bold'))中的text=dstr应该改为text=dstr.get()

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 10月1日
  • 已采纳回答 9月23日
  • 创建了问题 9月22日

悬赏问题

  • ¥15 grbl为何无法移动到比复位坐标更小的坐标?
  • ¥60 怎样隐藏win7系统进程?
  • ¥15 CBF预处理数据归一化的时候报错了如下图
  • ¥15 qt 转 msvc 后 Opencv 始终打不开视频!
  • ¥15 yolo v5中labelimg的作用
  • ¥15 国赛c题2021,没有理解这一串代码的意思,这样报错该怎么解决(语言-matlab)
  • ¥15 一、执行完中断程序后如何继续运行,二、中断结束后如何跳过中断触发前的点位(LOW点不要继续运行,可以运行UP点)(关键词-程序运行)
  • ¥15 if为什么跳过if 直接执行else 中文
  • ¥200 解决登录微信老版本限制封号问题
  • ¥15 mysql中时间处理问题