私信  •  关注

Henry Yik

Henry Yik 最近创建的主题
Henry Yik 最近回复了
6 年前
回复了 Henry Yik 创建的主题 » 需要在Python3.7中创建数字时钟的帮助

你可以用 root.after

import tkinter as tk

from datetime import datetime

root = tk.Tk()
root.title("Digital Clock")

def clock():
    now = datetime.now()
    timelabeled = ("%s/%s/%s   %s:%s:%s" % (now.day, now.month, now.year, now.hour, now.minute, now.second))
    w.config(text = timelabeled, )
    root.after(1000,clock)

w = tk.Label(font = (100))
w.pack()
clock()
root.mainloop()
5 年前
回复了 Henry Yik 创建的主题 » python tkinter-显示和执行不同进程的多个窗口

你可以发挥你的作用 processIncoming 检查标志,需要时暂停/继续。

class GuiPart:
    def __init__(self, master, queue, endCommand,newWindow):
        self.queue = queue
        self.pause = False
        ....

    def processIncoming(self):
        while self.queue.qsize() and not self.pause:
            try:
                msg = self.queue.get(0)
                print (msg)
                self.output.set(msg)
            except queue.Empty:
                pass
5 年前
回复了 Henry Yik 创建的主题 » 在pandas-python 3.x中使用group by执行countif

如果我理解正确,首先 set_index rating ,然后 groupby :

import numpy as np
import pandas as pd

np.random.seed(500)

e = {"rating":np.random.choice([2,4],100),
     "foo1": np.random.randint(0,2,100),
     "foo2": np.random.randint(0,2,100),
     "foo3": np.random.randint(0,2,100),
     "foo4": np.random.randint(0,2,100)}

df = pd.DataFrame(e)
df = df.set_index("rating")
print (df.groupby(df.index).apply(lambda x: x.ne(0).sum()))

#
        foo1  foo2  foo3  foo4
rating                        
2         21    21    24    19
4         32    26    24    30

我很好奇你为什么要用 selected_item = tree1.selection_set() .

从文档中:

选择集(*项)

项将成为新的选择。

在版本3.6中更改:项可以作为单独的参数传递,而不是 就像一个元组。

在我看来你应该用 tree.selection() 相反。

您正在处理列表列表。因此,您可以使用嵌套列表理解:

a = [[7.460143566, 9.373718262, 9.540244102, 9.843519211, 9.034710884, 10.71182728], [0.490880072, 0.637698293, 0.806753874, 0.906699121, 0.697924912, 0.949957848], [52.33952713, 69.05165863, 65.69918823, 67.53870392, 65.12568665, 72.78334045]]

b = [[(x-min(l))/(max(l)-min(l)) for x in l] for l in a]

print (b)

结果:

[[0.0, 0.5884873389626358, 0.6396995276767564, 0.7329666273317014, 0.4842313879485761, 1.0], 
[0.0, 0.3198112142984678, 0.688061628145554, 0.9057703742992778, 0.4510016620800218, 1.0],
[0.0, 0.8174664500409363, 0.6534818573661288, 0.7434609459640676, 0.625429283659689, 1.0]]
5 年前
回复了 Henry Yik 创建的主题 » 如何在python中向for循环添加项?

你不是在写 dict 到csv,所以你不必使用 Dictwriter . 你也可以用 zip 同时查看两个列表。

import csv

titles = [
    'April',
    'Apple',
    'Donkey'
]

texts = [
    'April description text...',
    'Apple description text...',
    'Donkey description text...'
]

with open('test1.csv', mode='w',newline="") as csv_file:
    writer = csv.writer(csv_file)
    writer.writerow(['TITLES', 'TEXT'])
    for x in zip(titles,texts):
        writer.writerow(x)
5 年前
回复了 Henry Yik 创建的主题 » 如何使用python和tkinter进行实时日期显示

datetime

from datetime import datetime

def tick():
    now = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
    clock.config(text=now)
    clock.after(200, tick)