小编Cab*_*abu的帖子

使用Flask适当地重载json编码和解码

我正在尝试向Flask JSON编码器/解码器添加一些重载以添加日期时间编码/解码,但只能通过“ hack”成功。

from flask import Flask, flash, url_for, redirect, render_template_string
from flask.json import JSONEncoder, JSONDecoder


template = """
<!DOCTYPE html>
<html><head><title>Test JSON encoder/decoder</title></head><body>
{% with messages = get_flashed_messages(with_categories=true) %}{% if messages %}{% for message in messages %}
<p>Flash: {{ message }}</p>
{% endfor %}{% endif %}{% endwith %}
<p>Flash should be: ['Flash message', 'success']</p>
<p><a href="{{ url_for('index') }}">Try again</a></p>
</body></html>
"""


class CustomJSONEncoder(JSONEncoder):
    """ Do nothing custom json encoder """
    def default(self, obj):
        # My custom logic here
        # …
Run Code Online (Sandbox Code Playgroud)

python session json decoding flask

5
推荐指数
1
解决办法
2135
查看次数

python 中的 tkinter 菜单栏中是否可以有图标

我得到什么:

菜单中不显示图标

我的代码:

self.menu_bar = tk.Menu(self)
...
self.read_menu = tk.Menu(self.menu_bar, tearoff=False)
self.menu_bar.add_cascade(label='Read', underline=0, state=tk.DISABLED, menu=self.read_menu)
self.read_menu.add_command(label='First Page', underline=0, image=self.read_first_image, compound=tk.LEFT,
                           command=self.menu_read_first, accelerator='Home', state=tk.DISABLED)
self.read_menu.add_command(label='Last Page', underline=1, image=self.read_last_image, compound=tk.LEFT,
                           command=self.menu_read_last, accelerator='End')
self.read_menu.add_command(label='Next Page', underline=0, image=self.read_next_image, compound=tk.LEFT,
                           command=self.menu_read_next, accelerator='PgDn')
self.read_menu.add_command(label='Previous Page', underline=0, image=self.read_previous_image, compound=tk.LEFT,
                           command=self.menu_read_previous, accelerator='PgUp', state=tk.DISABLED)
...
self.menu_bar.add_separator()
self.menu_bar.add_command(command=self.menu_read_first, image=self.read_first_image, state=tk.DISABLED)
self.menu_bar.add_command(command=self.menu_read_previous, image=self.read_previous_image, state=tk.DISABLED)
self.menu_bar.add_command(command=self.menu_read_next, image=self.read_next_image)
self.menu_bar.add_command(command=self.menu_read_last, image=self.read_last_image)
Run Code Online (Sandbox Code Playgroud)

可以看到,分隔符和图标没有显示在顶部菜单中,而是很好地显示在子菜单中

我做错了什么还是根本不可能?

python menu tkinter python-3.x

3
推荐指数
1
解决办法
1万
查看次数

标签 统计

python ×2

decoding ×1

flask ×1

json ×1

menu ×1

python-3.x ×1

session ×1

tkinter ×1