回答編集履歴

6

RPA を用いた解決策を追記

2022/04/15 11:53

投稿

teamikl
teamikl

スコア8664

test CHANGED
@@ -53,3 +53,8 @@
53
53
  ※ ~~座標データの渡し方は、引数にする等工夫してください。~~ 追記: コードに反映
54
54
  座標は、親ウィンドウの座標とサイズ(高さ)から求めます。
55
55
  情報の所得は winfo_ 系のメソッドを調べて下さい。
56
+
57
+ ----
58
+ ## C) ウィンドウのオートメーション
59
+
60
+ 内部的には (A) の方法ですが、RPA 系のツールを用いて操作可能な場合もあります。

5

タイトルバーの微調整

2022/04/15 03:40

投稿

teamikl
teamikl

スコア8664

test CHANGED
@@ -44,7 +44,7 @@
44
44
  root.update()
45
45
  x, y = root.winfo_x(), root.winfo_y()
46
46
  h = root.winfo_reqheight()
47
- pos = (x, y+h+20) # ※ +20 はタイトルバーの高さ補正。tkitner側ではタイトルバーのサイズを所得するAPIはありません。
47
+ pos = (x, y+h+30) # ※ +30 はタイトルバーの高さ補正。tkitner側ではタイトルバーのサイズを所得するAPIはありません。
48
48
  print(pos)
49
49
 
50
50
  askcolor(pos=pos)

4

タイトルバーのサイズについて注記

2022/04/15 03:39

投稿

teamikl
teamikl

スコア8664

test CHANGED
@@ -44,7 +44,7 @@
44
44
  root.update()
45
45
  x, y = root.winfo_x(), root.winfo_y()
46
46
  h = root.winfo_reqheight()
47
- pos = (x, y+h)
47
+ pos = (x, y+h+20) # ※ +20 はタイトルバーの高さ補正。tkitner側ではタイトルバーのサイズを所得するAPIはありません。
48
48
  print(pos)
49
49
 
50
50
  askcolor(pos=pos)

3

修正

2022/04/15 03:37

投稿

teamikl
teamikl

スコア8664

test CHANGED
@@ -50,6 +50,6 @@
50
50
  askcolor(pos=pos)
51
51
  ```
52
52
 
53
- ※ 座標データの渡し方は、引数にする等工夫してください。
53
+ ~~座標データの渡し方は、引数にする等工夫してください。~~ 追記: コードに反映
54
54
  座標は、親ウィンドウの座標とサイズ(高さ)から求めます。
55
55
  情報の所得は winfo_ 系のメソッドを調べて下さい。

2

コード修正

2022/04/15 03:36

投稿

teamikl
teamikl

スコア8664

test CHANGED
@@ -20,13 +20,17 @@
20
20
  askcolor 関数が提供されてますが、この関数に少し手を加える
21
21
 
22
22
  ```python
23
+ # NOTE: ライブラリのインストール pip install tkcolorpicker
23
24
 
25
+ import tkinter as tk
24
26
  from tkcolorpicker.colorpicker import ColorPicker
25
27
 
26
- def askcolor(color="red", parent=None, title="Color Chooser", alpha=False):
28
+ def askcolor(color="red", parent=None, title="Color Chooser", alpha=False, pos=None):
27
29
  col = ColorPicker(parent, color, alpha, title)
28
30
 
31
+ if pos:
32
+ x, y = pos
29
- col.wm_geometry("+10+10") # <--- ダイアログの座標を移動
33
+ col.wm_geometry(f"+{x}+{y}") # <--- ダイアログの座標を移動
30
34
 
31
35
  col.wait_window(col)
32
36
  res = col.get_color()
@@ -34,6 +38,16 @@
34
38
  return res[0], res[2]
35
39
  else:
36
40
  return None, None
41
+
42
+
43
+ root = tk.Tk()
44
+ root.update()
45
+ x, y = root.winfo_x(), root.winfo_y()
46
+ h = root.winfo_reqheight()
47
+ pos = (x, y+h)
48
+ print(pos)
49
+
50
+ askcolor(pos=pos)
37
51
  ```
38
52
 
39
53
  ※ 座標データの渡し方は、引数にする等工夫してください。

1

コード修正

2022/04/15 03:32

投稿

teamikl
teamikl

スコア8664

test CHANGED
@@ -23,7 +23,7 @@
23
23
 
24
24
  from tkcolorpicker.colorpicker import ColorPicker
25
25
 
26
- def askcolor(color="red", parent=None, title=_("Color Chooser"), alpha=False):
26
+ def askcolor(color="red", parent=None, title="Color Chooser", alpha=False):
27
27
  col = ColorPicker(parent, color, alpha, title)
28
28
 
29
29
  col.wm_geometry("+10+10") # <--- ダイアログの座標を移動