导入模块中的无线电按钮
我正在Python 3.10 Windows 11中创建GUI应用程序,并且已经变得很大。
为了简化它,我试图使用和理解
我想导入一个模块,该模块要求用户从radiobuttons网格中进行选择,其中包含缩略图,其中所选值返回到主程序。尽可能简化我已经编写了两个测试程序:testmain.py和testmodule.py。
他们不起作用,我开始认为我对模块的
任何指示都有根本的误解或帮助非常感谢 testmain是
from tkinter import *
import testmodule
testscreen=Toplevel(bg="green")
file_number=IntVar()
testmodule.buttons()
print(file_number.get())
testscreen.mainloop()
,testmodule是
from tkinter import *
def buttons():
testscreen=Toplevel(bg="lightblue1")
file_number=IntVar()
button1 = Radiobutton(testscreen,text=1,variable=file_number,value=1)
button1.pack
button2 = Radiobutton(testscreen,text=2,variable=file_number,value=2)
button2.pack
testscreen.wait_variable(file_number)
testscreen.destroy()
return(file_number.get())\\\
I am creating a gui application in python 3.10 windows 11 and it has become quite large.
To simplify it I am trying to use and understand modules
I would like to import a module that asks the user to choose from a grid of radiobuttons containing thumbnails with the chosen value returned to the main program. Simplifying as much as possible I have written two test programs, testmain.py and testmodule.py.
They don’t work and I am beginning to think I have a fundamental misunderstanding of modules
Any pointers or help much appreciated
testmain is
from tkinter import *
import testmodule
testscreen=Toplevel(bg="green")
file_number=IntVar()
testmodule.buttons()
print(file_number.get())
testscreen.mainloop()
and testmodule is
from tkinter import *
def buttons():
testscreen=Toplevel(bg="lightblue1")
file_number=IntVar()
button1 = Radiobutton(testscreen,text=1,variable=file_number,value=1)
button1.pack
button2 = Radiobutton(testscreen,text=2,variable=file_number,value=2)
button2.pack
testscreen.wait_variable(file_number)
testscreen.destroy()
return(file_number.get())\\\
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您要打开窗口时,请参阅主表单,不是
Toplevel
。 使用testmain.py的方式这就是您要打开另一个窗口时 ,请参阅
toplevwel
。这就是您使用testModule.py
的方式。您无法在TestModule开始时添加背景。您将获得一个错误
typeError:tk .__ init __()在
testmain
中获得了意外的关键字参数'bg',您不能使用
file> file> file_number = intvar()和
print(file_number.get()
)从另一个模块获取数据。因此,两者都会发表评论。在
testmodule.py
中,在第11行中添加打印功能。因此,您可以看到调试。顺便说一句,从tkinter导入 *我在
testmodule
中修改了WIRDCARD。
摘要:
在
testModule.py
,在第11行中,只需添加print()。ScreenShot:
When you want to open a window, refer to the main form, not
Toplevel
. That is the way you used testmain.pyWhen you want to open another window, refer as
Toplevwel
. That is the way you usedtestmodule.py
.You cannot add background at the start of testmodule. You will get an error
TypeError: Tk.__init__() got an unexpected keyword argument 'bg'
In
testmain
, you cannot usefile_number=IntVar()
andprint(file_number.get()
) to get data from another module. So comment out for both.In
testmodule.py
, in line 11 add a print function. So you can see debug.Btw, Don't used wildcard
from tkinter import *
I modified in
testmodule
.Snippet:
In
testmodule.py
, in line 11, just add print().Screenshot: