简体   繁体   English

输入字段未使用用户定义的模块进行更新

[英]The Entry fields are not being updated using user-defined modules

I have a master program in python3 that calls sub-programs via modules. 我在python3中有一个主程序,该主程序通过模块调用子程序。 This works fine, except that my modules don't update the Entry fields when changes are made elsewhere within the module. 效果很好,除了在模块中其他位置进行更改时,我的模块不会更新Entry字段。 The Module shows that values are put in the correct place, but the window isn't updated. 模块显示值已放置在正确的位置,但窗口未更新。 Here is an example of the master program:- 这是主程序的示例:

# test - master

from tkinter import *

root=Tk()
root.title("Test for the update problem")

import changeEntryfield

changeEntryfield.fun() # call to function inside module

root.mainloop()

# end of master program

And here is the module that is called (stored as "changeEntryfield.py"):- 这就是被调用的模块(存储为“ changeEntryfield.py”):

def fun():

    import tkinter 


    win=tkinter.Tk() # start a window

    g3=tkinter.StringVar()

    g3.set("text")

    a="something"

    field=tkinter.Entry(win,width=10,textvariable=g3)
    field.grid(column=1,row=0,sticky='W',padx=5,pady=5)

    grpslab3=tkinter.Label(win,text="The Field is: ")
    grpslab3.grid(column=0,row=0,sticky='W',padx=5,pady=5)

    # now do changes to field value

    g3.set(a)
    print ("1. In Entry, field = ",field['textvariable'])

    field['textvariable']=g3.get()
    print ("2. In Entry, field = ",field['textvariable'])

    field.config(textvariable=g3.get())
    print ("3. In Entry, field = ",field['textvariable'])

    field['textvariable']=a
    print ("4. In Entry, field = ",field['textvariable'])

    win.mainloop()

# end of module

Any suggestions? 有什么建议么?

Tkinter isn't designed to work this way. Tkinter并非以这种方式工作。 A complete program should only ever have a single instance of Tk at one time. 一个完整的程序一次只能有一个Tk实例。 You should create instances of Toplevel in your sub-programs. 您应该在子程序中创建Toplevel实例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 附加用户定义的模块以进行自动搜索 - Appending user-defined modules for automatic searching Django:未捕获用户定义的异常 - Django: User-defined exception not being caught 在使用 Dockerfile 和 docker-compose 的 Python 部署中,用户定义模块的“没有名为 x 的模块” - "No module named x" for user-defined modules in Python deployment using Dockerfile and docker-compose **更新** Python 基于用户定义的方法编程 - **UPDATED** Python Programming based on user-defined methods 如何在cygwin中导入用户定义的python模块? - How to import user-defined python modules in cygwin? 使用用户定义的规则对项目进行排序 - Sorting items using user-defined rule Python用户定义的异常字符串被拆分 - Python user-defined exception string being split 跨模块的Python用户定义的全局变量:运行其他模块时调用它们的问题 - Python User-Defined Global Variables Across Modules: Issues calling them when other modules are run 在python中使用用户定义的密钥进行RSA加密 - RSA Encryption using the user-defined keys in python 在表服务查询中使用用户定义的列表 - Using a user-defined list in table-service query
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM