Home>
I use python's Tkinter.
I was able to display multiple calculators on the screen, but if I displayed four at the same time, this time the calculator was only displayed and I couldn't calculate numbers without typing. How can I improve it so that four calculators can be displayed and used at the same time?
Now I write four codes below and four calculators are displayed, but I can't use the calculator function at the same time.
You can display multiple calculators but you cannot use the calculator at the same time
Applicable source code`` Python Tkinter from tkinter import *
root = Tk ()
root.title ("Player1")
def func (v):
var1.set (var1.get () + v)
def clear ():
var1.set ("")
def all_clear ():
var1.set ("")
def result ():
try:
var1.set (eval (var1.get ()))
except SyntaxError:
var1.set ("SyntaxError")
except ZeroDivisionError:
var1.set ("ZeroDivisionError")
except NameError:
var1.set ("NameError")
var1 = StringVar ()
label = Label (root, textvariable = var1, fg = "# ffffff", bg = "# 000000", anchor = E, height = 2)
label.grid (row = 0, column = 0, columnspan = 4, sticky = "EW")
#First row
btn_c = Button (root, text = "C", command = clear, width = 5, height = 2)
btn_c.grid (row = 1, column = 2)
btn_ac = Button (root, text = "AC", command = all_clear, width = 5, height = 2)
btn_ac.grid (row = 1, column = 3)
btn_add = Button (root, text = "+", command = lambda: func ("+"), width = 5, height = 2)
btn_add.grid (row = 2, column = 3)
# 2nd row
btn_7 = Button (root, text = "7", command = lambda: func ("7"), width = 5, height = 2)
btn_7.grid (row = 2, column = 0)
btn_8 = Button (root, text = "8", command = lambda: func ("8"), width = 5, height = 2)
btn_8.grid (row = 2, column = 1)
btn_9 = Button (root, text = "9", command = lambda: func ("9"), width = 5, height = 2)
btn_9.grid (row = 2, column = 2)
# 3rd row
btn_4 = Button (root, text = "4", command = lambda: func ("4"), width = 5, height = 2)
btn_4.grid (row = 3, column = 0)
btn_5 = Button (root, text = "5", command = lambda: func ("5"), width = 5, height = 2)
btn_5.grid (row = 3, column = 1)
btn_6 = Button (root, text = "6", command = lambda: func ("6"), width = 5, height = 2)
btn_6.grid (row = 3, column = 2)
btn_mul = Button (root, text = "*", command = lambda: func ("*"), width = 5, height = 2)
btn_mul.grid (row = 3, column = 3)
# 4th row
btn_1 = Button (root, text = "1", command = lambda: func ("1"), width = 5, height = 2)
btn_1.grid (row = 4, column = 0)
btn_2 = Button (root, text = "2", command = lambda: func ("2"), width = 5, height = 2)
btn_2.grid (row = 4, column = 1)
btn_3 = Button (root, text = "3", command = lambda: func ("3"), width = 5, height = 2)
btn_3.grid (row = 4, column = 2)
btn_sub = Button (root, text = "-", command = lambda: func ("-"), width = 5, height = 2)
btn_sub.grid (row = 4, column = 3)
# 5th column
btn_0 = Button (root, text = "0", command = lambda: func ("0"), width = 5, height = 2)
btn_0.grid (row = 5, column = 0)
btn_eq = Button (root, text = "=", command = result, width = 5, height = 2)
btn_eq.grid (row = 5, column = 3)
root.mainloop ()
Because I'm a beginner in programming, I didn't find any useful information to search.
Supplemental information (FW/tool version etc.)Python 3.6.8 shell
-
Answer # 1
Related articles
- python - i want to display multiple data in one area
- python - display two windows of pyqtgraf and tkinter at the same time
- python - [tkinter] multiple selectable combobox
- sql - when you want to display multiple values in one column
- python - read multiple audio files (wav files)
- python 3x - unintended behavior of python3 tkinter binding
- python - [tkinter] [py installer] unable to execute exe file
- python 3x - multiple outputs from a list of tuples
- python - about multiple processing and loop processing in discordpy
- python matplotlibpyplot i get an error trying to display a moving average on a candlestick chart
- python3 tkinter i want to be able to input only character strings in a fixed format
- javascript - i want to display a modal window from multiple buttons
- how to scrape in python and display in a browser?
- python 3x - python3 tkinter toplevel behaves differently than intended
- i want to get the value from a constant in python and display it
- python - i want to display an image with pysimplegui, but an error occurs
- (python) i want to convert multiple json files with different columns into one csv format
- python - cannot inherit a class with multiple arguments
- display images by drag and drop on wxpython gui
- excel python i want to get the display result instead of the conditional statement
Related questions
- python : Syntax highlighting itself, tkinter
- python : I need to paint the color of the checkerboard like on a chessboard
- python : tkinter member reference fails
- binding to the button of the function of launching another script in tkinter python
- python : Is it possible to bring the parent window to the fore when selecting a tkinter child window?
- How to stretch a ttk.Treeview in Python?
- python : Displaying mqtt data by a client in a Label in real time
- How to pass data through clicking on a button in python Tkinter
- python : Webbrowser reopens pages
- How to shorten field declarations in Python with Tkinter?
Tkinter is not so detailed ...
If you want to create more than one, you should define a class.
If you want to create multiple top level windows, use the Toplevel component.
I tried to display 4 other than the root window.
All four exits when you close the root window.
Information on which window is processed is passed to the argument self.