我有一个类,我想通过执行以下操作导入def函数:
import <file>
Run Code Online (Sandbox Code Playgroud)
但是当我试着打电话时,它说无法找到def.我也尝试过:
from <file> import <def>
Run Code Online (Sandbox Code Playgroud)
但后来它说没有定义全局名称'x'.
那我该怎么做呢?
编辑:
这是我想要做的一个例子.在file1.py我有:
var = "hi"
class a:
def __init__(self):
self.b()
import file2
a()
Run Code Online (Sandbox Code Playgroud)
在file2.py我有:
def b(self):
print(var)
Run Code Online (Sandbox Code Playgroud)
它只是给了我一个错误.
好的,我有这个简单的代码:
import tkinter.filedialog
from tkinter import *
import tkinter.ttk as ttk
root = Tk()
root.title('test')
nb = ttk.Notebook(root)
nb.pack(fill='both', expand='yes')
f1 = Text(root)
f2 = Text(root)
f3 = Text(root)
nb.add(f1, text='page1')
nb.add(f2, text='page2')
nb.add(f3, text='page3')
root.mainloop()
Run Code Online (Sandbox Code Playgroud)
我只是想知道,在 tkinter 中处理带有文本的多个选项卡的最佳方法是什么?就像如果我想删除“page2”上的所有文本或在“page3”上插入一些内容,我该怎么做?
我知道如何为小部件设置样式表(使用setStyleSheet),但是有什么方法可以读取小部件的样式表吗?
如何获取光标下的文本?因此,如果我将鼠标悬停在它上面并且单词"hi",我可以阅读它吗?我想我需要用QTextCursor.WordUnderCursor做一些事情,但我不确定是什么.有帮助吗?
这就是我现在正在努力解决的问题:
textCursor = text.cursorForPosition(event.pos());
textCursor.select(QTextCursor.WordUnderCursor);
text.setTextCursor(textCursor);
word = textCursor.selectedText();
Run Code Online (Sandbox Code Playgroud)
我现在正在选择文本,所以我可以看到它.
编辑2:
我真正想要做的是在文本中的某些单词上显示工具提示.
有没有办法获得当前选中的标签的数量/索引?我有一个标签字典,但我需要能够获得当前活动的标签.