爱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日

悬赏问题

  • ¥30 电脑误删了手机的照片怎么恢复?
  • ¥15 (标签-python|关键词-char)
  • ¥15 python+selenium,在新增时弹出了一个输入框
  • ¥15 苹果验机结果的api接口哪里有??单次调用1毛钱及以下。
  • ¥20 学生成绩管理系统设计
  • ¥15 来一个cc穿盾脚本开发者
  • ¥15 CST2023安装报错
  • ¥15 使用diffusionbert生成文字 结果是PAD和UNK怎么办
  • ¥15 有人懂怎么做大模型的客服系统吗?卡住了卡住了
  • ¥20 firefly-rk3399上启动卡住了