回答編集履歴
2
コードの修正
answer
CHANGED
@@ -62,6 +62,7 @@
|
|
62
62
|
root.after(1000, rp) #1000ミリ秒後にrpを実行
|
63
63
|
|
64
64
|
def start():
|
65
|
+
global RPC
|
65
66
|
RPC = Presence(client_id, pipe=0)
|
66
67
|
RPC.connect()
|
67
68
|
mbox.showinfo("info", "ステータス表示を有効化しました")
|
1
コードの修正、追記
answer
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
threadingを使わない方法になってしまいますが、
|
2
2
|
while Trueの中にウインドウを更新するroot.update()を挟めばフリーズしません。
|
3
|
-
```
|
3
|
+
```Python
|
4
4
|
import psutil
|
5
5
|
from pypresence import Presence
|
6
6
|
import time
|
@@ -29,14 +29,45 @@
|
|
29
29
|
time.sleep(1)
|
30
30
|
root.update()
|
31
31
|
|
32
|
+
button1 = tk.Button(text="有効化", font=("", 30), width=15, height=5, command=rp)
|
33
|
+
button1.pack()
|
32
34
|
|
33
|
-
|
35
|
+
root.mainloop()
|
34
|
-
th = threading.Thread(target=rp)
|
35
|
-
|
36
|
+
```
|
36
37
|
|
37
38
|
|
39
|
+
root.after()を使う方法もあります。個人的にはこっちのほうが好きです
|
40
|
+
```Python
|
41
|
+
import psutil
|
42
|
+
from pypresence import Presence
|
43
|
+
import time
|
44
|
+
import platform
|
45
|
+
import tkinter as tk
|
46
|
+
from tkinter import messagebox as mbox
|
47
|
+
import threading
|
38
48
|
|
49
|
+
root = tk.Tk()
|
50
|
+
root.geometry("500x300")
|
51
|
+
|
52
|
+
client_id = 'クライアントID'
|
53
|
+
|
54
|
+
n = "\n"
|
55
|
+
|
56
|
+
starttime = time.time()
|
57
|
+
|
58
|
+
def rp():
|
59
|
+
cpu_per = round(psutil.cpu_percent(), 1)
|
60
|
+
mem_per = round(psutil.virtual_memory().percent, 1)
|
61
|
+
RPC.update(start=int(starttime), details="メモリ使用率: " + str(mem_per) + "%",state="CPU使用率:"+str(cpu_per))
|
62
|
+
root.after(1000, rp) #1000ミリ秒後にrpを実行
|
63
|
+
|
64
|
+
def start():
|
65
|
+
RPC = Presence(client_id, pipe=0)
|
66
|
+
RPC.connect()
|
67
|
+
mbox.showinfo("info", "ステータス表示を有効化しました")
|
68
|
+
rp()
|
69
|
+
|
39
|
-
button1 = tk.Button(text="有効化", font=("", 30), width=15, height=5, command=
|
70
|
+
button1 = tk.Button(text="有効化", font=("", 30), width=15, height=5, command=start)
|
40
71
|
button1.pack()
|
41
72
|
|
42
73
|
root.mainloop()
|