因此,我尝试使用以下代码将简单样式应用于labelframe小部件:
import sys
if sys.version_info[0] == 2: # Just checking your Python version to import Tkinter properly.
import Tkinter as tk
import ttk as ttk
else:
import tkinter as tk
from tkinter.ttk import ttk as ttk
root = tk.Tk()
bls = ttk.Style()
bls.configure('Black.TLabelFrame', background="#222222")
dayframe = ttk.Labelframe(root, style='Black.TLabelFrame', height=200, width=150, relief=tk.SUNKEN,
text="Hello")
dayframe.grid(row=1, column=1, padx=5)
root.mainloop()
Run Code Online (Sandbox Code Playgroud)
但是,当我运行此代码时,我收到错误消息:
TclError:找不到布局Black.TLabelFrame
我不明白我做错了什么......
这是我的 HTML:
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>BookInc</title>
<link rel="stylesheet" href="style.css">
</head>
<body style="background-color:white;">
<div id= "mainPage">
</div>
<script src="test.js"></script>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
和我的 javascript:
var btn = document.createElement('input');
btn.type = "button";
btn.className = "btn";
btn.value = "Negociate";
btn.onclick = console.log("hello");
document.getElementById('mainPage').appendChild(btn);
Run Code Online (Sandbox Code Playgroud)
当我的按钮创建时,onclick 事件会自动触发(我在控制台中打印 hello 而不单击按钮)然后不起作用。当我检查页面时,我意识到我的按钮不再有 onclick(只有类和值)
我不明白为什么所以任何帮助将不胜感激。谢谢。