导入模块中的无线电按钮

发布于 2025-02-06 20:06:21 字数 860 浏览 0 评论 0原文

我正在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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

红ご颜醉 2025-02-13 20:06:21

当您要打开窗口时,请参阅主表单,不是 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

摘要:

import tkinter as tk
import testmodule

 
testscreen = tk.Tk(bg='green')
testscreen.configure(bg='green')
 
testmodule.buttons()
 
testscreen.mainloop()

testModule.py,在第11行中,只需添加print()。

testscreen.wait_variable(file_number)
    print(file_number.get())

    testscreen.destroy()
    return(file_number.get())

ScreenShot:

“

When you want to open a window, refer to the main form, not Toplevel. That is the way you used testmain.py

When you want to open another window, refer as Toplevwel. That is the way you used testmodule.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 use file_number=IntVar() and print(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:

import tkinter as tk
import testmodule

 
testscreen = tk.Tk(bg='green')
testscreen.configure(bg='green')
 
testmodule.buttons()
 
testscreen.mainloop()

In testmodule.py, in line 11, just add print().

testscreen.wait_variable(file_number)
    print(file_number.get())

    testscreen.destroy()
    return(file_number.get())

Screenshot:

enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文