-1

please click here to see the image.i want to link my python function with the entry box.suppose if i add a function to a button in gui. if i click the button then function output should be displayed on python entry box.but im getting output in python shell.please help me out from this.
@Jundullah output of your codeimage1
output is replaceing with new input, insteed i need to print beside.image2

**** here is the code****

from tkinter import *

root = Tk()

text_input = StringVar()

operator = ""

txtDisplay= Entry(font=('arial',70,'bold italic'),textvariable=text_input , 
                  bd=30,insertwidth=4,bg="#b0e0e6", justify = "center")

root.title("Alphabet Pattern")

txtDisplay.grid(columnspan=10)

def A():

    """This function will print alphabet A"""

    for i in range(7):

        for j in range(7):

            if ((j==0 or j==6)) and i!=0 or ((i==0 or i==3) and (j>0 and 
                                                                     j<6)):
                print("*",end="")

            else:

                print(end=" ")

        print()

    print()

def C():

    """This function will print alphabet C"""

    for row in range(7):

        for col in range(7):

            if (col==0 and (row!=0 and row!=6) or ((row==0 or row==6) and 
                                                                (col>0))):

                print("*",end="");

            else:

                print(end=" ")

        print()

    print()

#first button

A1 = Button(padx=16,pady=16,bd=8,fg="#000000",font=('arial',30,'bold 
italic'),text="A",bg="#b0e0e6e",command= A ).grid(row=3, column=0)

#second button

C1 = Button(padx=16,pady=16,bd=8,fg="#000000",font=('arial',30,'bold 
italic'),text="C",bg="#b0e0e6",command=  C).grid(row=4, column=2)

root.mainloop()

please give me any suggestions to solve the above code.

sukesh
  • 41
  • 4

1 Answers1

0

Use this instead of the print function:

use this:

var = Label(padx=32,pady=32,fg="#000000",font=('arial',30,'bold 
          italic'),text="something",bg="#b0e0e6").grid(row=4, column=2)

It works but needs to be tidy! :)

you should try it:

from tkinter import *

root = Tk()

text_input = StringVar()

operator = ""

txtDisplay= Entry(font=('arial',70,'bold italic'),textvariable=text_input , 
bd=30,insertwidth=4,bg="#b0e0e6", justify = "center")

root.title("Alphabet Pattern")

txtDisplay.grid(columnspan=10)

c = ""
a = ""

def A():
    global a
    a = ""
    """This function will print alphabet A"""

    for i in range(7):

        for j in range(7):

            if ((j==0 or j==6)) and i!=0 or ((i==0 or i==3) and (j>0 and j<6)):
                a += "*"

            else:
                a += " "
        a += "\n"

    var["text"] = a

def C():
    global c
    c = ""
    """This function will print alphabet C"""

    for row in range(7):

        for col in range(7):

            if (col==0 and (row!=0 and row!=6) or ((row==0 or row==6) and 
(col>0))):
                c += "*"
            else:
                c += " "
        c += "\n"

    var["text"] = c

var = Label(root)
var.config(text="Allah",bd=0,fg="orange",width=0,height=0,bg="#000000",font= 
                                                         ("courier new",40))
var.place(relx=1,x=-500, y=250, anchor=W)

#first button

A1 = Button(padx=16,pady=16,bd=8,fg="#000000",font=('arial',30,'bold 
italic'),text="A",bg="#0f0f0f",command= A ).grid(row=3, column=0)

#second button

C1 = Button(padx=16,pady=16,bd=8,fg="#000000",font=('arial',30,'bold 
italic'),text="C",bg="#0f0f0f",command=  C).grid(row=4, column=2)

root.mainloop()
Jundullah
  • 113
  • 2
  • 11
  • your answer is very near to the question. but the problem is the output is not printing in entry box, in the above code you created a new widget to print the output.and the second problem is in the widget the output is replaceing. **i'm unable to upload the screenshots to this comment, so will upload the screenshots in my question , please refer my question. thank you @Jundullah** – sukesh Jan 01 '19 at 12:56
  • refer question , i have given links there – sukesh Jan 01 '19 at 13:50
  • @sukesh maybe it solves this problem:https://stackoverflow.com/a/16374273/10696411 – Jundullah Jan 01 '19 at 14:00
  • yes, but in functions i written a pattern logic, when i click the button patterns output unable to print in entry box , if i change my function (pattern to normal sentence) it is working. i already tried that logic which u said , but i dont get the required output . @Jundullah – sukesh Jan 01 '19 at 14:06
  • The image links you sent are not working. i need to see them! – Jundullah Jan 01 '19 at 14:13