質問編集履歴

2

コードを見やすく編集

2019/11/22 03:33

投稿

patapat
patapat

スコア5

test CHANGED
File without changes
test CHANGED
@@ -180,6 +180,8 @@
180
180
 
181
181
 
182
182
 
183
+ root.mainloop()
184
+
183
185
  ```
184
186
 
185
187
 

1

コードを見やすく編集

2019/11/22 03:33

投稿

patapat
patapat

スコア5

test CHANGED
File without changes
test CHANGED
@@ -1,12 +1,8 @@
1
- ### 前提・実現したいこと
2
-
3
-
4
-
5
1
  pythonのTkinterを使っています。
6
2
 
7
3
  画面に電卓を複数表示させることはできたのですが、4つ同時に表示させると今度は電卓が表示されるだけで数字が打ち込めずに計算できなくなりました。電卓を4つ表示させ同時に使えるようにするにはどのように改善したらよいでしょうか?
8
4
 
9
- ■■な機能を実装中に以下のエラメッセージ発生しました。
5
+ 今は下のドを4つ書き電卓4つ表示されるようにはなりましたが、同時に電卓の機能を使うことができないです
10
6
 
11
7
 
12
8
 
@@ -30,7 +26,7 @@
30
26
 
31
27
 
32
28
 
33
-
29
+ ```ここに言語を入力
34
30
 
35
31
  root = Tk()
36
32
 
@@ -184,503 +180,15 @@
184
180
 
185
181
 
186
182
 
187
-
188
-
189
-
190
-
191
-
192
-
193
-
194
-
195
-
196
-
197
-
198
-
199
- root = Tk()
200
-
201
-
202
-
203
-
204
-
205
- root.title("Player2")
206
-
207
-
208
-
209
-
210
-
211
- def func(v):
212
-
213
- var1.set(var1.get() + v)
214
-
215
-
216
-
217
-
218
-
219
- def clear():
220
-
221
- var1.set("")
222
-
223
-
224
-
225
-
226
-
227
- def all_clear():
228
-
229
- var1.set("")
230
-
231
-
232
-
233
-
234
-
235
- def result():
236
-
237
- try:
238
-
239
- var1.set(eval(var1.get()))
240
-
241
- except SyntaxError:
242
-
243
- var1.set("SyntaxError")
244
-
245
- except ZeroDivisionError:
246
-
247
- var1.set("ZeroDivisionError")
248
-
249
- except NameError:
250
-
251
- var1.set("NameError")
252
-
253
-
254
-
255
-
256
-
257
- var1 = StringVar()
258
-
259
- label = Label(root, textvariable=var1, fg="#ffffff", bg="#000000", anchor=E, height=2)
260
-
261
- label.grid(row=0, column=0, columnspan=4, sticky="EW")
262
-
263
-
264
-
265
- #1列目
266
-
267
- btn_c = Button(root, text="C", command=clear, width=5, height=2)
268
-
269
- btn_c.grid(row=1, column=2)
270
-
271
- btn_ac = Button(root, text="AC", command=all_clear, width=5, height=2)
272
-
273
- btn_ac.grid(row=1, column=3)
274
-
275
- btn_add = Button(root, text="+", command=lambda: func("+"), width=5, height=2)
276
-
277
- btn_add.grid(row=2, column=3)
278
-
279
-
280
-
281
- #2列目
282
-
283
- btn_7 = Button(root, text="7", command=lambda: func("7"), width=5, height=2)
284
-
285
- btn_7.grid(row=2, column=0)
286
-
287
- btn_8 = Button(root, text="8", command=lambda: func("8"), width=5, height=2)
288
-
289
- btn_8.grid(row=2, column=1)
290
-
291
- btn_9 = Button(root, text="9", command=lambda: func("9"), width=5, height=2)
292
-
293
- btn_9.grid(row=2, column=2)
294
-
295
-
296
-
297
- #3列目
298
-
299
- btn_4 = Button(root, text="4", command=lambda: func("4"), width=5, height=2)
300
-
301
- btn_4.grid(row=3, column=0)
302
-
303
- btn_5 = Button(root, text="5", command=lambda: func("5"), width=5, height=2)
304
-
305
- btn_5.grid(row=3, column=1)
306
-
307
- btn_6 = Button(root, text="6", command=lambda: func("6"), width=5, height=2)
308
-
309
- btn_6.grid(row=3, column=2)
310
-
311
- btn_mul = Button(root, text="*", command=lambda: func("*"), width=5, height=2)
312
-
313
- btn_mul.grid(row=3, column=3)
314
-
315
-
316
-
317
- #4列目
318
-
319
- btn_1 = Button(root, text="1", command=lambda: func("1"), width=5, height=2)
320
-
321
- btn_1.grid(row=4, column=0)
322
-
323
- btn_2 = Button(root, text="2", command=lambda: func("2"), width=5, height=2)
324
-
325
- btn_2.grid(row=4, column=1)
326
-
327
- btn_3 = Button(root, text="3", command=lambda: func("3"), width=5, height=2)
328
-
329
- btn_3.grid(row=4, column=2)
330
-
331
- btn_sub = Button(root, text="-", command=lambda: func("-"), width=5, height=2)
332
-
333
- btn_sub.grid(row=4, column=3)
334
-
335
-
336
-
337
- #5列目
338
-
339
- btn_0 = Button(root, text="0", command=lambda: func("0"), width=5, height=2)
340
-
341
- btn_0.grid(row=5, column=0)
342
-
343
-
344
-
345
- btn_eq = Button(root, text="=", command=result, width=5, height=2)
346
-
347
- btn_eq.grid(row=5, column=3)
348
-
349
-
350
-
351
-
352
-
353
-
354
-
355
-
356
-
357
-
358
-
359
-
360
-
361
-
362
-
363
- root = Tk()
364
-
365
-
366
-
367
-
368
-
369
- root.title("Player3")
370
-
371
-
372
-
373
-
374
-
375
- def func(v):
376
-
377
- var1.set(var1.get() + v)
378
-
379
-
380
-
381
-
382
-
383
- def clear():
384
-
385
- var1.set("")
386
-
387
-
388
-
389
-
390
-
391
- def all_clear():
392
-
393
- var1.set("")
394
-
395
-
396
-
397
-
398
-
399
- def result():
400
-
401
- try:
402
-
403
- var1.set(eval(var1.get()))
404
-
405
- except SyntaxError:
406
-
407
- var1.set("SyntaxError")
408
-
409
- except ZeroDivisionError:
410
-
411
- var1.set("ZeroDivisionError")
412
-
413
- except NameError:
414
-
415
- var1.set("NameError")
416
-
417
-
418
-
419
-
420
-
421
- var1 = StringVar()
422
-
423
- label = Label(root, textvariable=var1, fg="#ffffff", bg="#000000", anchor=E, height=2)
424
-
425
- label.grid(row=0, column=0, columnspan=4, sticky="EW")
426
-
427
-
428
-
429
- #1列目
430
-
431
- btn_c = Button(root, text="C", command=clear, width=5, height=2)
432
-
433
- btn_c.grid(row=1, column=2)
434
-
435
- btn_ac = Button(root, text="AC", command=all_clear, width=5, height=2)
436
-
437
- btn_ac.grid(row=1, column=3)
438
-
439
- btn_add = Button(root, text="+", command=lambda: func("+"), width=5, height=2)
440
-
441
- btn_add.grid(row=2, column=3)
442
-
443
-
444
-
445
- #2列目
446
-
447
- btn_7 = Button(root, text="7", command=lambda: func("7"), width=5, height=2)
448
-
449
- btn_7.grid(row=2, column=0)
450
-
451
- btn_8 = Button(root, text="8", command=lambda: func("8"), width=5, height=2)
452
-
453
- btn_8.grid(row=2, column=1)
454
-
455
- btn_9 = Button(root, text="9", command=lambda: func("9"), width=5, height=2)
456
-
457
- btn_9.grid(row=2, column=2)
458
-
459
-
460
-
461
- #3列目
462
-
463
- btn_4 = Button(root, text="4", command=lambda: func("4"), width=5, height=2)
464
-
465
- btn_4.grid(row=3, column=0)
466
-
467
- btn_5 = Button(root, text="5", command=lambda: func("5"), width=5, height=2)
468
-
469
- btn_5.grid(row=3, column=1)
470
-
471
- btn_6 = Button(root, text="6", command=lambda: func("6"), width=5, height=2)
472
-
473
- btn_6.grid(row=3, column=2)
474
-
475
- btn_mul = Button(root, text="*", command=lambda: func("*"), width=5, height=2)
476
-
477
- btn_mul.grid(row=3, column=3)
478
-
479
-
480
-
481
- #4列目
482
-
483
- btn_1 = Button(root, text="1", command=lambda: func("1"), width=5, height=2)
484
-
485
- btn_1.grid(row=4, column=0)
486
-
487
- btn_2 = Button(root, text="2", command=lambda: func("2"), width=5, height=2)
488
-
489
- btn_2.grid(row=4, column=1)
490
-
491
- btn_3 = Button(root, text="3", command=lambda: func("3"), width=5, height=2)
492
-
493
- btn_3.grid(row=4, column=2)
494
-
495
- btn_sub = Button(root, text="-", command=lambda: func("-"), width=5, height=2)
496
-
497
- btn_sub.grid(row=4, column=3)
498
-
499
-
500
-
501
- #5列目
502
-
503
- btn_0 = Button(root, text="0", command=lambda: func("0"), width=5, height=2)
504
-
505
- btn_0.grid(row=5, column=0)
506
-
507
-
508
-
509
- btn_eq = Button(root, text="=", command=result, width=5, height=2)
510
-
511
- btn_eq.grid(row=5, column=3)
512
-
513
-
514
-
515
-
516
-
517
-
518
-
519
-
520
-
521
-
522
-
523
-
524
-
525
-
526
-
527
-
528
-
529
-
530
-
531
- root = Tk()
532
-
533
-
534
-
535
-
536
-
537
- root.title("Player4")
538
-
539
-
540
-
541
-
542
-
543
- def func(v):
544
-
545
- var1.set(var1.get() + v)
546
-
547
-
548
-
549
-
550
-
551
- def clear():
552
-
553
- var1.set("")
554
-
555
-
556
-
557
-
558
-
559
- def all_clear():
560
-
561
- var1.set("")
562
-
563
-
564
-
565
-
566
-
567
- def result():
568
-
569
- try:
570
-
571
- var1.set(eval(var1.get()))
572
-
573
- except SyntaxError:
574
-
575
- var1.set("SyntaxError")
576
-
577
- except ZeroDivisionError:
578
-
579
- var1.set("ZeroDivisionError")
580
-
581
- except NameError:
582
-
583
- var1.set("NameError")
584
-
585
-
586
-
587
-
588
-
589
- var1 = StringVar()
590
-
591
- label = Label(root, textvariable=var1, fg="#ffffff", bg="#000000", anchor=E, height=2)
592
-
593
- label.grid(row=0, column=0, columnspan=4, sticky="EW")
594
-
595
-
596
-
597
- #1列目
598
-
599
- btn_c = Button(root, text="C", command=clear, width=5, height=2)
600
-
601
- btn_c.grid(row=1, column=2)
602
-
603
- btn_ac = Button(root, text="AC", command=all_clear, width=5, height=2)
604
-
605
- btn_ac.grid(row=1, column=3)
606
-
607
- btn_add = Button(root, text="+", command=lambda: func("+"), width=5, height=2)
608
-
609
- btn_add.grid(row=2, column=3)
610
-
611
-
612
-
613
- #2列目
614
-
615
- btn_7 = Button(root, text="7", command=lambda: func("7"), width=5, height=2)
616
-
617
- btn_7.grid(row=2, column=0)
618
-
619
- btn_8 = Button(root, text="8", command=lambda: func("8"), width=5, height=2)
620
-
621
- btn_8.grid(row=2, column=1)
622
-
623
- btn_9 = Button(root, text="9", command=lambda: func("9"), width=5, height=2)
624
-
625
- btn_9.grid(row=2, column=2)
626
-
627
-
628
-
629
- #3列目
630
-
631
- btn_4 = Button(root, text="4", command=lambda: func("4"), width=5, height=2)
632
-
633
- btn_4.grid(row=3, column=0)
634
-
635
- btn_5 = Button(root, text="5", command=lambda: func("5"), width=5, height=2)
636
-
637
- btn_5.grid(row=3, column=1)
638
-
639
- btn_6 = Button(root, text="6", command=lambda: func("6"), width=5, height=2)
640
-
641
- btn_6.grid(row=3, column=2)
642
-
643
- btn_mul = Button(root, text="*", command=lambda: func("*"), width=5, height=2)
644
-
645
- btn_mul.grid(row=3, column=3)
646
-
647
-
648
-
649
- #4列目
650
-
651
- btn_1 = Button(root, text="1", command=lambda: func("1"), width=5, height=2)
652
-
653
- btn_1.grid(row=4, column=0)
654
-
655
- btn_2 = Button(root, text="2", command=lambda: func("2"), width=5, height=2)
656
-
657
- btn_2.grid(row=4, column=1)
658
-
659
- btn_3 = Button(root, text="3", command=lambda: func("3"), width=5, height=2)
660
-
661
- btn_3.grid(row=4, column=2)
662
-
663
- btn_sub = Button(root, text="-", command=lambda: func("-"), width=5, height=2)
664
-
665
- btn_sub.grid(row=4, column=3)
666
-
667
-
668
-
669
- #5列目
670
-
671
- btn_0 = Button(root, text="0", command=lambda: func("0"), width=5, height=2)
672
-
673
- btn_0.grid(row=5, column=0)
674
-
675
-
676
-
677
- btn_eq = Button(root, text="=", command=result, width=5, height=2)
678
-
679
- btn_eq.grid(row=5, column=3)
680
-
681
-
682
-
683
- root.mainloop()
183
+ ```
184
+
185
+
186
+
187
+
188
+
189
+
190
+
191
+
684
192
 
685
193
 
686
194
 
@@ -692,7 +200,7 @@
692
200
 
693
201
 
694
202
 
695
- プログラミング初心者なため検索しても有力な情報がなかったため、大きく試していることなし。
203
+ プログラミング初心者なため検索しても有力な情報がなかったため、大きく試していることないので今のところ自分の力では解決するすべなし。
696
204
 
697
205
 
698
206