我在Win机器上运行Tkinter 3.5,当我运行此代码时,我得到两个窗口.我只期待一个.顺便说一下,我从网上得到了代码.它工作正常,除了困扰我第二个(在backgorund)窗口.基本上是一个小部件,通过按钮导航到不同的窗口(页面).
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
try:
import Tkinter as tk # Python2
except ImportError:
import tkinter as tk # Python3
class Wizard(tk.Toplevel):
def __init__(self, npages, master=None):
self.pages = []
self.current = 0
tk.Toplevel.__init__(self)
self.attributes('-topmost', True)
for page in range(npages):
self.pages.append(tk.Frame(self))
self.pages[0].pack(fill='both', expand=1)
self.__wizard_buttons()
def onQuit(self):
pass
def __wizard_buttons(self):
for indx, frm in enumerate(self.pages):
btnframe = tk.Frame(frm, bd=1, bg='#3C3B37')
btnframe.pack(side='bottom', fill='x')
nextbtn = tk.Button(btnframe, bd=0, bg='#F2F1F0', activebackground='#F58151', highlightcolor='red', cursor='hand2', text="Siguiente >>", width=10, command=self.__next_page)
nextbtn.pack(side='right', anchor='e', padx=5, …Run Code Online (Sandbox Code Playgroud) 同事,
我在raspberry pi中收到序列信息,需要将其发送到浏览器.我使用python捕获数据和烧瓶作为Web框架.我面临的主要问题是如何像每一秒一样自动刷新网页.实际上只刷新变量.正在浏览几个帖子,每个人似乎都指向AJAX/JSON/JQUERY,但对于我的简单应用程序,似乎很多.有什么简单的方法可以做我需要的吗?
python应用程序
from flask import Flask,render_template
app = Flask(__name__)
@app.route('/')
def index():
return render_template('index.html', ent_direc ="120")
if __name__ == '__main__':
app.run(debug=True, host='0.0.0.0')
Run Code Online (Sandbox Code Playgroud)
在这种情况下ent_direc(固定为120用于测试,但是通过pyserial接收)是我传递给我的html页面的变量,在那里我有java脚本(+ html canvas)来显示一个量表.
index.html - 只是几行
<!DOCTYPE html>
<html>
<body>
<canvas id="canvas" width="400" height="400" style="background-color:#ffffff"></canvas>
<script>
var canvas = document.getElementById("canvas");
var ctx = canvas.getContext("2d");
var radius = canvas.height / 2;
var ent_direc;
ctx.translate(radius, radius);
radius = radius * 0.90;
drawClock();
function drawClock() {
drawFace(ctx, radius);
drawNumbers(ctx, radius);
drawTime(ctx, radius);
drawMajorticks(ctx,radius);
drawMinorticks(ctx,radius);
}
Run Code Online (Sandbox Code Playgroud)
更新:
我一直在努力,但需要更多的帮助.似乎我的服务器端应用程序(app.py)没有"点击"网页index.html.我这样说是因为当我刷新页面时,我确实在网页中看到了我的变量,只是文本.我的所有画布都没有显示.实际上删除了index.html和相同的结果.这是app.py,它基本上从串行接收两个变量并返回它们.我的文件结构是:webapp/app.py templates/index.html static/jquery-1.11.3.min.js …