【问题标题】:Module naming overlaps模块命名重叠
【发布时间】:2020-11-12 19:13:29
【问题描述】:

我将Tkinter 与GUI 一起使用,并使用根窗口内的按钮。 我还想在MatplotLib 图表中使用Button,它允许我退出图表(并且将来可能用于其他用途)。 唯一的问题是它们都使用相同的标签Button。这两个标签有不同的语法,所以我只能有Tkinter 按钮或Matplotlib 按钮。

我确定这是一个非常业余的问题,但有没有办法指定这个 Button 是一个 tkinter 按钮,而另一个 Button 是一个 matplotlib 按钮?

下面是代码示例:

from matplotlib.widgets import Slider, Button, RadioButtons

from tkinter import *

btn = Button(root, text="Plot", command=graph).pack()

【问题讨论】:

  • 这就是为什么你不应该使用通配符导入。

标签: python matplotlib tkinter syntax


【解决方案1】:

找到了答案,但这可能对某些人有帮助

你可以改用

将 tkinter 导入为 tk

然后每次你想要一个 tkinter 函数时,你可以通过写“tk”来指定它。在它之前。

例如: tk.Button 在这种情况下,它将专门使用 Button 的 tkinter 版本

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-05-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-23
    • 2011-11-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多