回答編集履歴

9

もっといい方法がみつかりました

2022/09/01 16:49

投稿

shiracamus
shiracamus

スコア5406

test CHANGED
@@ -1,3 +1,26 @@
1
+ 追記: もっといい方法がみつかりました。
2
+
3
+ ```py
4
+ import tkinter as tk
5
+
6
+ #新規ウィンドウを作成
7
+ root = tk.Tk()
8
+ root.title("sample")
9
+ root.attributes("-fullscreen", True)
10
+
11
+ width = root.winfo_screenwidth()
12
+ height = root.winfo_screenheight()
13
+
14
+ frame = tk.Frame(root)
15
+ frame.pack()
16
+ canvas = tk.Canvas(frame, width=width, height=height, bg='black', highlightthickness=0, relief='ridge')
17
+ canvas.pack()
18
+
19
+ root.after(3000, root.quit)
20
+ root.mainloop()
21
+ ```
22
+
23
+
1
24
  pack ではなく place を使ってみました。
2
25
 
3
26
  ```python

8

ずらし幅を大きめに修正(canvas描画時にずらした部分が表示されないのでご注意ください)

2022/09/01 16:39

投稿

shiracamus
shiracamus

スコア5406

test CHANGED
@@ -14,7 +14,7 @@
14
14
  frame = tk.Frame(root)
15
15
  frame.place(width=width, height=height)
16
16
  canvas = tk.Canvas(frame, bg='black')
17
- canvas.place(x=-1, y=-1, width=width + 2, height=height + 2)
17
+ canvas.place(x=-5, y=-5, width=width + 10, height=height + 10)
18
18
 
19
19
  root.after(3000, root.quit)
20
20
  root.mainloop()

7

最小限の指定に変更

2022/09/01 16:08

投稿

shiracamus
shiracamus

スコア5406

test CHANGED
@@ -12,9 +12,9 @@
12
12
  height = root.winfo_screenheight()
13
13
 
14
14
  frame = tk.Frame(root)
15
- frame.place(x=-1, y=-1, width=width + 1, height=height + 1)
15
+ frame.place(width=width, height=height)
16
- canvas = tk.Canvas(frame, width=width, height=height, bg='black')
16
+ canvas = tk.Canvas(frame, bg='black')
17
- canvas.place(x=0, y=0, width=width + 2, height=height + 2)
17
+ canvas.place(x=-1, y=-1, width=width + 2, height=height + 2)
18
18
 
19
19
  root.after(3000, root.quit)
20
20
  root.mainloop()

6

位置調整

2022/09/01 16:01

投稿

shiracamus
shiracamus

スコア5406

test CHANGED
@@ -12,9 +12,9 @@
12
12
  height = root.winfo_screenheight()
13
13
 
14
14
  frame = tk.Frame(root)
15
- frame.place(x=-5, y=-5, width=width + 10, height=height + 10)
15
+ frame.place(x=-1, y=-1, width=width + 1, height=height + 1)
16
16
  canvas = tk.Canvas(frame, width=width, height=height, bg='black')
17
- canvas.place(x=0, y=0, width=width + 10, height=height + 10)
17
+ canvas.place(x=0, y=0, width=width + 2, height=height + 2)
18
18
 
19
19
  root.after(3000, root.quit)
20
20
  root.mainloop()

5

位置調整

2022/09/01 15:57

投稿

shiracamus
shiracamus

スコア5406

test CHANGED
@@ -12,7 +12,7 @@
12
12
  height = root.winfo_screenheight()
13
13
 
14
14
  frame = tk.Frame(root)
15
- frame.place(x=-5, y=-5, width=width + 5, height=height + 5)
15
+ frame.place(x=-5, y=-5, width=width + 10, height=height + 10)
16
16
  canvas = tk.Canvas(frame, width=width, height=height, bg='black')
17
17
  canvas.place(x=0, y=0, width=width + 10, height=height + 10)
18
18
 

4

位置調整

2022/09/01 15:55

投稿

shiracamus
shiracamus

スコア5406

test CHANGED
@@ -12,7 +12,7 @@
12
12
  height = root.winfo_screenheight()
13
13
 
14
14
  frame = tk.Frame(root)
15
- frame.place(x=-5, y=-5, width=width + 10, height=height + 10)
15
+ frame.place(x=-5, y=-5, width=width + 5, height=height + 5)
16
16
  canvas = tk.Canvas(frame, width=width, height=height, bg='black')
17
17
  canvas.place(x=0, y=0, width=width + 10, height=height + 10)
18
18
 

3

pack を place に変更

2022/09/01 15:52

投稿

shiracamus
shiracamus

スコア5406

test CHANGED
@@ -1,4 +1,4 @@
1
- pack する際に padx と pady 0 にしてみてください
1
+ pack ではなく place使ってみました
2
2
 
3
3
  ```python
4
4
  import tkinter as tk
@@ -8,12 +8,13 @@
8
8
  root.title("sample")
9
9
  root.attributes("-fullscreen", True)
10
10
 
11
+ width = root.winfo_screenwidth()
12
+ height = root.winfo_screenheight()
13
+
11
14
  frame = tk.Frame(root)
12
- frame.pack()
15
+ frame.place(x=-5, y=-5, width=width + 10, height=height + 10)
13
- canvas = tk.Canvas(frame, width=root.winfo_screenwidth(),
16
+ canvas = tk.Canvas(frame, width=width, height=height, bg='black')
14
- height=root.winfo_screenheight(),
15
- bg='black')
16
- canvas.pack(padx=0, pady=0)
17
+ canvas.place(x=0, y=0, width=width + 10, height=height + 10)
17
18
 
18
19
  root.after(3000, root.quit)
19
20
  root.mainloop()

2

Canvasを使うように修正しました

2022/09/01 15:19

投稿

shiracamus
shiracamus

スコア5406

test CHANGED
@@ -1,4 +1,4 @@
1
- これでどうでょう?
1
+ pack する際に padx と pady を 0 にてみてください。
2
2
 
3
3
  ```python
4
4
  import tkinter as tk
@@ -8,10 +8,12 @@
8
8
  root.title("sample")
9
9
  root.attributes("-fullscreen", True)
10
10
 
11
- frame = tk.Frame(root, width=root.winfo_screenwidth(),
11
+ frame = tk.Frame(root)
12
- height=root.winfo_screenheight(),
13
- bg='green')
14
12
  frame.pack()
13
+ canvas = tk.Canvas(frame, width=root.winfo_screenwidth(),
14
+ height=root.winfo_screenheight(),
15
+ bg='black')
16
+ canvas.pack(padx=0, pady=0)
15
17
 
16
18
  root.after(3000, root.quit)
17
19
  root.mainloop()

1

不要行削除

2022/09/01 10:04

投稿

shiracamus
shiracamus

スコア5406

test CHANGED
@@ -7,7 +7,6 @@
7
7
  root = tk.Tk()
8
8
  root.title("sample")
9
9
  root.attributes("-fullscreen", True)
10
- print(root.size())
11
10
 
12
11
  frame = tk.Frame(root, width=root.winfo_screenwidth(),
13
12
  height=root.winfo_screenheight(),