回答編集履歴
2
コードの修正
test
CHANGED
@@ -126,6 +126,8 @@
|
|
126
126
|
|
127
127
|
def start():
|
128
128
|
|
129
|
+
global RPC
|
130
|
+
|
129
131
|
RPC = Presence(client_id, pipe=0)
|
130
132
|
|
131
133
|
RPC.connect()
|
1
コードの修正、追記
test
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
while Trueの中にウインドウを更新するroot.update()を挟めばフリーズしません。
|
4
4
|
|
5
|
-
```
|
5
|
+
```Python
|
6
6
|
|
7
7
|
import psutil
|
8
8
|
|
@@ -60,21 +60,7 @@
|
|
60
60
|
|
61
61
|
|
62
62
|
|
63
|
-
|
64
|
-
|
65
|
-
def callback():
|
66
|
-
|
67
|
-
th = threading.Thread(target=rp)
|
68
|
-
|
69
|
-
th.start()
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
button1 = tk.Button(text="有効化", font=("", 30), width=15, height=5, command=
|
63
|
+
button1 = tk.Button(text="有効化", font=("", 30), width=15, height=5, command=rp)
|
78
64
|
|
79
65
|
button1.pack()
|
80
66
|
|
@@ -83,3 +69,79 @@
|
|
83
69
|
root.mainloop()
|
84
70
|
|
85
71
|
```
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
root.after()を使う方法もあります。個人的にはこっちのほうが好きです
|
78
|
+
|
79
|
+
```Python
|
80
|
+
|
81
|
+
import psutil
|
82
|
+
|
83
|
+
from pypresence import Presence
|
84
|
+
|
85
|
+
import time
|
86
|
+
|
87
|
+
import platform
|
88
|
+
|
89
|
+
import tkinter as tk
|
90
|
+
|
91
|
+
from tkinter import messagebox as mbox
|
92
|
+
|
93
|
+
import threading
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
root = tk.Tk()
|
98
|
+
|
99
|
+
root.geometry("500x300")
|
100
|
+
|
101
|
+
|
102
|
+
|
103
|
+
client_id = 'クライアントID'
|
104
|
+
|
105
|
+
|
106
|
+
|
107
|
+
n = "\n"
|
108
|
+
|
109
|
+
|
110
|
+
|
111
|
+
starttime = time.time()
|
112
|
+
|
113
|
+
|
114
|
+
|
115
|
+
def rp():
|
116
|
+
|
117
|
+
cpu_per = round(psutil.cpu_percent(), 1)
|
118
|
+
|
119
|
+
mem_per = round(psutil.virtual_memory().percent, 1)
|
120
|
+
|
121
|
+
RPC.update(start=int(starttime), details="メモリ使用率: " + str(mem_per) + "%",state="CPU使用率:"+str(cpu_per))
|
122
|
+
|
123
|
+
root.after(1000, rp) #1000ミリ秒後にrpを実行
|
124
|
+
|
125
|
+
|
126
|
+
|
127
|
+
def start():
|
128
|
+
|
129
|
+
RPC = Presence(client_id, pipe=0)
|
130
|
+
|
131
|
+
RPC.connect()
|
132
|
+
|
133
|
+
mbox.showinfo("info", "ステータス表示を有効化しました")
|
134
|
+
|
135
|
+
rp()
|
136
|
+
|
137
|
+
|
138
|
+
|
139
|
+
button1 = tk.Button(text="有効化", font=("", 30), width=15, height=5, command=start)
|
140
|
+
|
141
|
+
button1.pack()
|
142
|
+
|
143
|
+
|
144
|
+
|
145
|
+
root.mainloop()
|
146
|
+
|
147
|
+
```
|