标题:关于tkinter中textvariable的问题,请帮我一下,谢谢了。
取消只看楼主
wangjx236007
Rank: 1
等 级:新手上路
帖 子:36
专家分:0
注 册:2021-3-2
结帖率:40%
已结贴  问题点数:10 回复次数:2 
关于tkinter中textvariable的问题,请帮我一下,谢谢了。
各位高手,我用tkinter做了一个窗体test2,单独运行没有问题。但通过窗体test1进入窗体test2时,就不能自动填写日期,请帮我,非常感谢。
test2.py
import datetime
from tkinter import *
from tkinter.ttk import *
from tkinter import ttk
# from datetime import datetime
class mainWin:
    def __init__(self):
        self.loginwin=Tk()
        self.loginwin.title("主窗体")
        self.width = self.loginwin.winfo_screenwidth() * 0.2
        self.height = self.loginwin.winfo_screenheight() * 0.2
        self.screenwidth = self.loginwin.winfo_screenwidth()
        self.screenheight = self.loginwin.winfo_screenheight()
        self.alignstr = '%dx%d+%d+%d' % (
            self.width, self.height, (self.screenwidth - self.width) / 2, (self.screenheight - self.height) / 2)
        self.loginwin.geometry(self.alignstr)
        self.date_now=StringVar()
        self.riqi=Label(self.loginwin,text="自动填当前日期:").place(relx=0.01,rely=0.2)
        self.lab=Label(self.loginwin,textvariable=self.date_now, font="宋体 10", relief="groove", state="disable")
        self.lab.place(relx=0.3,rely=0.2,relwidth=0.3)
        self.btn=Button(self.loginwin,text="填日期",command=self.st_date).place(relx=0.4,rely=0.4)

        self.loginwin.mainloop()
    def st_date(self):
        date=datetime.datetime.now()

        bh2 = date.strftime("%Y-%m-%d")
        self.date_now.set(bh2)


test1.py
from tkinter import *
from tkinter.ttk import *
from tkinter import ttk
from tkinter.messagebox import *

import test2



class Win:
    def __init__(self):
        self.loginwin=Tk()
        self.loginwin.title("系统登录")
        self.width = self.loginwin.winfo_screenwidth() * 0.2
        self.height = self.loginwin.winfo_screenheight() * 0.2
        self.screenwidth = self.loginwin.winfo_screenwidth()
        self.screenheight = self.loginwin.winfo_screenheight()
        self.alignstr = '%dx%d+%d+%d' % (
            self.width, self.height, (self.screenwidth - self.width) / 2, (self.screenheight - self.height) / 2)
        self.loginwin.geometry(self.alignstr)
        self.litl=Label(self.loginwin,text="延伸服务系统",font="宋体 14 bold").place(relx=0.18,rely=0.14)
        self.separator = ttk.Separator(self.loginwin).place(relx=0, rely=0.3, relwidth=1)
        self.lab=Label(self.loginwin,text="用 户 名:",font="宋体 12").place(relx=0.15,rely=0.4)
        self.username=Entry(self.loginwin,font="宋体 12")
        self.username.place(relx=0.4,rely=0.4)
        self.labb2 = Label(self.loginwin, text="用 户 名:", font="宋体 12").place(relx=0.15, rely=0.6)
        self.password = Entry(self.loginwin, font="宋体 12",show="*")
        self.password.place(relx=0.4, rely=0.6)
        self.bnt1=Button(self.loginwin,text="登录",command=self.login).place(relx=0.28,rely=0.8)
        self.bnt1 = Button(self.loginwin, text="退出", command= self.loginwin.destroy).place(relx=0.58, rely=0.8)
        self.loginwin.mainloop()
        # main_win.mainWin()
    def login(self):

        username=self.username.get()
        password=self.password.get()
        if username=="" and password=="":
            showinfo("错误","请输入用户名和密码")
        else:
            if username=="wjx" and password=="123456":
                test2.mainWin()
            else:
                self.username.delete(0,END)
                self.password.delete(0,END)

                showinfo("警告","请输入正确的用户名和密码!")

Win()
搜索更多相关主题的帖子: from tkinter username text import 
2022-10-16 15:38
wangjx236007
Rank: 1
等 级:新手上路
帖 子:36
专家分:0
注 册:2021-3-2
得分:0 
请帮我一下,我可以付费。
2022-10-17 09:51
wangjx236007
Rank: 1
等 级:新手上路
帖 子:36
专家分:0
注 册:2021-3-2
得分:0 
非常感谢
2022-10-19 07:43



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-510342-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.158819 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved