- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
AttributeError: MyGUI instance has no attribute 'tk'
另外,如何使创建的窗口具有固定大小并且不能用鼠标调整大小?或者在通过单击按钮更改标签值之后。
我的代码:
from Tkinter import*
class MyGUI(Frame):
def __init__(self):
self.__mainWindow = Tk()
#lbl
self.labelText = 'label message'
self.depositLabel = Label(self.__mainWindow, text = self.labelText)
#buttons
self.hi_there = Button(self.__mainWindow)
self.hi_there["text"] = "Hello",
self.hi_there["command"] = self.testeo
self.QUIT = Button(self.__mainWindow)
self.QUIT["text"] = "QUIT"
self.QUIT["fg"] = "red"
self.QUIT["command"] = self.quit
#place on view
self.depositLabel.pack()
self.hi_there.pack() #placed in order!
self.QUIT.pack()
#What does it do?
mainloop()
def testeo(self):
self.depositLabel['text'] = 'c2value'
print "testeo"
def depositCallBack(self,event):
self.labelText = 'change the value'
print(self.labelText)
self.depositLabel['text'] = 'change the value'
myGUI = MyGUI()
怎么了?谢谢
最佳答案
您应该调用Frame
的 super 构造函数。不确定,但我猜这将设置 quit
命令所依赖的 tk
属性。之后,无需创建您自己的 Tk()
实例。
def __init__(self):
Frame.__init__(self)
# self.__mainWindow = Tk()
当然,您还必须相应地更改小部件的构造函数调用,例如,
self.hi_there = Button(self) # self, not self.__mainWindow
或更好(或至少更短):直接在构造函数中设置所有属性:
self.hi_there = Button(self, text="Hello", command=self.testeo)
同时将 self.pack()
添加到您的构造函数中。
(或者,您可以将退出命令更改为 self.__mainWindow.quit
,但我认为以上是创建框架的更好样式,请参见例如 here。)
关于python-2.7 - Python Tkinter 实例没有属性 'tk',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19533189/
我想向 tk.Tk 和 tk.Toplevel 的实例添加 2 个方法。前者作为应用程序根窗口存在,后者由用户创建任意次数。每个 tk.Toplevel 代表应用程序的不同功能,目前有 13 种变体。
尝试创建 Listbox 的子类,以便我可以创建一个新的 KeyListbox from tkinter import * class KeyListbox(Listbox): def __
以下是错误: $ perl ftper.plUse of uninitialized value $id in hash element at /usr/lib/perl5/vendor_perl/5
我正在尝试使用 tk.Scale 来更改 tk.IntVar。我可以在第一个 tk 窗口上执行此操作,但不能在第二个窗口上执行。为什么? 看看这个可怜的样本: import tkinter as tk
我输入了我的框架比例,但我不确定如何在我的标签中显示这个比例的值。每次秤移动时我都需要更新它。我怎样才能做到这一点? self.options_settings.framepripojeni6 = F
这个video向我介绍了 X 的问题以及 Wayland 协议(protocol)的替代方案。多年来,Wayland 协议(protocol)的采用似乎在不断增长。 我的问题: tkinter 和 t
这些天我经常看到这一行:tk.Tk.__init__(self,*args,**kwargs)并且不明白它的用途。我的问题不是 *args 和 **kwargs)。 例如,在此处的这些代码行中: cl
这个问题涉及Python和Tkinter。 我想同时使用两个不同的 ttk 主题,例如一个 Tkinter 窗口中的“clam”和“vista”。所以我写了这个: import tkinter as
从 Tk 8.5 开始,Tk 开始使用基于原生的 UI 组件——按钮、滚动条等。我想知道 C++/Tk 是否支持这种原生 GUI 方法? 最佳答案 据我所知,C++/Tk 是基于 Tk 8.4(如果是
我无法让 ruby 成功地 require 'tk'。我正在使用 rvm、ruby 2.0.0、ActiveTcl-8.6 和 Ubuntu 12.04 LTS。我已经运行了随 ActiveTcl
我想用最有效的方式来限制用户不输入数字以外的任何内容。例如:当他们在条目中输入字母时,该条目将被清除。有没有什么方法可以用最少的结构改变来做到这一点? 这是我的代码:[??????标志是我被困的地方]
我真的很喜欢Perl/Tk ,但已经得出的意见认为它是 DOA。我认为 Tcl::Tk和 Tkx是更好的解决方案。假设我放弃 Perl/Tk . Tcl::Tk 是“最受支持”的路线吗? (自 200
我正在尝试使用 perl:latest 和 activestate/circleci-activeperl:latest 图像在 ubuntu:16.04 容器上运行使用 Tk 模块制作的简单 per
我曾经使用 tk.Scale 的 digits 属性来确保 Label 或 Spinbox 中的数字> 在 slider 移动时显示固定的小数位数。比如 3.456, 4444.567, 555555
问题就在标题中,本质上是:如何在设置 Entry 的 textvariable 后继续调用 validatecommand 回调?这是最低工作示例 (MWE): import tkinter as t
在Perl/Tk应用程序中,我想将带有任意Unicode文件名的文件拖放到小工具上。。有一个正在运行的DropSite示例:Windows资源管理器中的perl tk拖放文件夹,但它不能处理包含Uni
我在 macOS BigSur 上通过 VMWare 使用 Ubuntu 20.04.2 LTS。我安装了最新版本的 tcl、tcl-dev、tk 和 tk-dev - 版本 8.6。我想编译 Arc
我组装 Tk 窗口的方式有问题(在 Win XP 下使用 R tcltk 和 tcltk2) library(tcltk) library(tcltk2) expandTk <- function()
我想在 Textdocument 的特定行中写入,但我的代码有问题,我不知道错误在哪里。 set fp [open C:/Users/user/Desktop/tst/settings.txt w]
当在 TK 中创建新的顶层或按钮时,需要输入路径名。我看过一个基本代码,如下所示: toplevel .a ... button .a.b ... 我的问题是:点与字母的处理方式是否不同?它们是某种创
我是一名优秀的程序员,十分优秀!