0 Replies - 497 Views - Last Post: 07 November 2014 - 08:56 AM Rate Topic: -----

#1 soccr8699   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 26
  • Joined: 19-March 14

Input text into a python.py file

Posted 07 November 2014 - 08:56 AM

I made an executable tkinter program in python. I was wondering if there was a way to make another program and input the text into the existing program at a certain point.

I want this program:

with open('Tkintergraph.py', 'a') as f:
    el = input()
    ef = input()
    f.write('xpoint= {}\nypoint= {}\n'.format(el,ef))


to input the writing to this code:

from tkinter import *
def checkered(canvas, line_distance): 
   for x in range(line_distance, canvas_width, line_distance):
      canvas.create_line(x, 0, x, canvas_height, fill="black")
   for y in range(line_distance,canvas_height,line_distance):
      canvas.create_line(0, y, canvas_width, y, fill="black")

###############################################################################

#This is where i want to input the text
root = Tk()
canvas_width = 1000
canvas_height = 1000
w = Canvas(root, 
           width=canvas_width,
           height=canvas_height)
checkered(w,20)           
w.pack()
a = int(canvas_height / 2)
w.create_line(0, a, canvas_width, a, 
              fill="red",width=3)
b = int(canvas_width / 2)
w.create_line(b, 0, b,canvas_height, 
              fill = "red",width=3)
w.create_text(5, ((canvas_height/2)-10)
              ,text="x",font=12)
w.create_text(b+10 ,5
              ,text='y',font=12)
w.create_text(b+10,a-10
              ,text='0',font=10)   
w.create_oval(b-5,a-5,b+5,a+5 
            ,fill = 'black')
if xpoint < 0:
   if ypoint > 0:
      xplace = (canvas_width/2)-(20*abs(xpoint))
      yplace = (canvas_height/2)-(20*abs(ypoint))
   if ypoint == 0:
      xplace = (canvas_width/2)-(20*abs(xpoint))
      yplace = (canvas_height/2)-(20*abs(ypoint))
   if ypoint < 0:
      xplace = (canvas_width/2)-(20*abs(xpoint))
      yplace = (canvas_height/2)+(20*abs(ypoint))
if xpoint == 0:
   if ypoint > 0:
         xplace = (canvas_width/2)-(20*abs(xpoint))
         yplace = (canvas_height/2)-(20*abs(ypoint))
   if ypoint == 0:
         xplace = (canvas_width/2)-(20*abs(xpoint))
         yplace = (canvas_height/2)-(20*abs(ypoint))
   if ypoint < 0:
         xplace = (canvas_width/2)-(20*abs(xpoint))
         yplace = (canvas_height/2)+(20*abs(ypoint))   
if xpoint > 0:
   if ypoint > 0:
         xplace = (canvas_width/2)+(20*abs(xpoint))
         yplace = (canvas_height/2)-(20*abs(ypoint))
   if ypoint == 0:
         xplace = (canvas_width/2)+(20*abs(xpoint))
         yplace = (canvas_height/2)-(20*abs(ypoint))
   if ypoint < 0:
         xplace = (canvas_width/2)+(20*abs(xpoint))
         yplace = (canvas_height/2)+(20*abs(ypoint))   
w.create_text(xplace,yplace,
              text='•',font=('Arial',20,'bold'),fill='red')
mainloop()



I've searched for how to do this online, but i could never find out how to do it with a .py document. Just letting you all know that i am very much a novice and any help would be appreciated

Is This A Good Question/Topic? 0
  • +

Page 1 of 1