I program the calculator, I met the setting function problem





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







-1















I implemented shape of calculator.
I want the command of Button, but I met the function error.
Please help the function setting.
If I click the button, then want to show the text of button.



This is my code.



import numpy as np
from tkinter import *
window = Tk()
window.title("My Calculator")

#버튼 입력 함수 설정
def click():
display.insert(0, button_array[i,j])

#계산 결과 표시할 위치
display = Entry(window, width=33, bg="yellow")
display.grid(row=0, column=0, columnspan=5)

#버튼 리스트로 만든 뒤 array 형태로 변경
button_list = [
'7','8','9','/','C',
'4','5','6','*',' ',
'1','2','3','-',' ',
'0','.','=','+',' ']
button_array = np.array(button_list).reshape(4,5)

for i in range(4):
for j in range(5):
b = Button(window, text=button_array[i,j], width=5, command=click)
b.grid(row=i+1, column=j)


window.mainloop()


Please help me and sorry about I'm not good at english.










share|improve this question


















  • 1





    Please edit the question and add the actual error (the stacktrace will also be helpful).

    – Todor Minakov
    Nov 24 '18 at 8:56











  • I am in the development stage of calculator. I want to set if I click the button, that number or operation will be showen in display(Entry line). How to set the function of buttons? Please give me a hint

    – 최영효
    Nov 25 '18 at 6:50




















-1















I implemented shape of calculator.
I want the command of Button, but I met the function error.
Please help the function setting.
If I click the button, then want to show the text of button.



This is my code.



import numpy as np
from tkinter import *
window = Tk()
window.title("My Calculator")

#버튼 입력 함수 설정
def click():
display.insert(0, button_array[i,j])

#계산 결과 표시할 위치
display = Entry(window, width=33, bg="yellow")
display.grid(row=0, column=0, columnspan=5)

#버튼 리스트로 만든 뒤 array 형태로 변경
button_list = [
'7','8','9','/','C',
'4','5','6','*',' ',
'1','2','3','-',' ',
'0','.','=','+',' ']
button_array = np.array(button_list).reshape(4,5)

for i in range(4):
for j in range(5):
b = Button(window, text=button_array[i,j], width=5, command=click)
b.grid(row=i+1, column=j)


window.mainloop()


Please help me and sorry about I'm not good at english.










share|improve this question


















  • 1





    Please edit the question and add the actual error (the stacktrace will also be helpful).

    – Todor Minakov
    Nov 24 '18 at 8:56











  • I am in the development stage of calculator. I want to set if I click the button, that number or operation will be showen in display(Entry line). How to set the function of buttons? Please give me a hint

    – 최영효
    Nov 25 '18 at 6:50
















-1












-1








-1








I implemented shape of calculator.
I want the command of Button, but I met the function error.
Please help the function setting.
If I click the button, then want to show the text of button.



This is my code.



import numpy as np
from tkinter import *
window = Tk()
window.title("My Calculator")

#버튼 입력 함수 설정
def click():
display.insert(0, button_array[i,j])

#계산 결과 표시할 위치
display = Entry(window, width=33, bg="yellow")
display.grid(row=0, column=0, columnspan=5)

#버튼 리스트로 만든 뒤 array 형태로 변경
button_list = [
'7','8','9','/','C',
'4','5','6','*',' ',
'1','2','3','-',' ',
'0','.','=','+',' ']
button_array = np.array(button_list).reshape(4,5)

for i in range(4):
for j in range(5):
b = Button(window, text=button_array[i,j], width=5, command=click)
b.grid(row=i+1, column=j)


window.mainloop()


Please help me and sorry about I'm not good at english.










share|improve this question














I implemented shape of calculator.
I want the command of Button, but I met the function error.
Please help the function setting.
If I click the button, then want to show the text of button.



This is my code.



import numpy as np
from tkinter import *
window = Tk()
window.title("My Calculator")

#버튼 입력 함수 설정
def click():
display.insert(0, button_array[i,j])

#계산 결과 표시할 위치
display = Entry(window, width=33, bg="yellow")
display.grid(row=0, column=0, columnspan=5)

#버튼 리스트로 만든 뒤 array 형태로 변경
button_list = [
'7','8','9','/','C',
'4','5','6','*',' ',
'1','2','3','-',' ',
'0','.','=','+',' ']
button_array = np.array(button_list).reshape(4,5)

for i in range(4):
for j in range(5):
b = Button(window, text=button_array[i,j], width=5, command=click)
b.grid(row=i+1, column=j)


window.mainloop()


Please help me and sorry about I'm not good at english.







python calculator






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 24 '18 at 7:44









최영효최영효

4




4








  • 1





    Please edit the question and add the actual error (the stacktrace will also be helpful).

    – Todor Minakov
    Nov 24 '18 at 8:56











  • I am in the development stage of calculator. I want to set if I click the button, that number or operation will be showen in display(Entry line). How to set the function of buttons? Please give me a hint

    – 최영효
    Nov 25 '18 at 6:50
















  • 1





    Please edit the question and add the actual error (the stacktrace will also be helpful).

    – Todor Minakov
    Nov 24 '18 at 8:56











  • I am in the development stage of calculator. I want to set if I click the button, that number or operation will be showen in display(Entry line). How to set the function of buttons? Please give me a hint

    – 최영효
    Nov 25 '18 at 6:50










1




1





Please edit the question and add the actual error (the stacktrace will also be helpful).

– Todor Minakov
Nov 24 '18 at 8:56





Please edit the question and add the actual error (the stacktrace will also be helpful).

– Todor Minakov
Nov 24 '18 at 8:56













I am in the development stage of calculator. I want to set if I click the button, that number or operation will be showen in display(Entry line). How to set the function of buttons? Please give me a hint

– 최영효
Nov 25 '18 at 6:50







I am in the development stage of calculator. I want to set if I click the button, that number or operation will be showen in display(Entry line). How to set the function of buttons? Please give me a hint

– 최영효
Nov 25 '18 at 6:50














1 Answer
1






active

oldest

votes


















0














What you can do is set a StringVar object, as set it as the display's "textvariable" attribute (when creating the display).
Then on each change of the text, use the set method of the StringVar to change the text.



Try looking at this example



Good Luck,
Dan






share|improve this answer
























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53456207%2fi-program-the-calculator-i-met-the-setting-function-problem%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    What you can do is set a StringVar object, as set it as the display's "textvariable" attribute (when creating the display).
    Then on each change of the text, use the set method of the StringVar to change the text.



    Try looking at this example



    Good Luck,
    Dan






    share|improve this answer




























      0














      What you can do is set a StringVar object, as set it as the display's "textvariable" attribute (when creating the display).
      Then on each change of the text, use the set method of the StringVar to change the text.



      Try looking at this example



      Good Luck,
      Dan






      share|improve this answer


























        0












        0








        0







        What you can do is set a StringVar object, as set it as the display's "textvariable" attribute (when creating the display).
        Then on each change of the text, use the set method of the StringVar to change the text.



        Try looking at this example



        Good Luck,
        Dan






        share|improve this answer













        What you can do is set a StringVar object, as set it as the display's "textvariable" attribute (when creating the display).
        Then on each change of the text, use the set method of the StringVar to change the text.



        Try looking at this example



        Good Luck,
        Dan







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 24 '18 at 8:09









        dan rdan r

        62




        62
































            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53456207%2fi-program-the-calculator-i-met-the-setting-function-problem%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            這個網誌中的熱門文章

            Xamarin.form Move up view when keyboard appear

            Post-Redirect-Get with Spring WebFlux and Thymeleaf

            Anylogic : not able to use stopDelay()