Python Forum
How to work with multiple files and tkinter?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to work with multiple files and tkinter?
#1
I have a beginners question about importing files and not being able to use a function in this file because it can't 'look back'.

I have two files. main.py:
from tkinter import *
from function import drawLine
master = Tk()

canvas_width = 80
canvas_height = 40
w = Canvas(master, 
           width=canvas_width,
           height=canvas_height)
w.pack()

y = int(canvas_height / 2)

drawLine()

mainloop()
and function.py:
def drawLine():
	w.create_line(0, y, canvas_width, y, fill="#476042")
I understand that 'function.py' cannot look into 'main.py'. How to write a function in 'function.py' that draws a line in the 'main.py' canvas? I hope someone can teach me about the way people work usually with drawing something on a canvas that is in another file :)
Reply


Messages In This Thread
How to work with multiple files and tkinter? - by philipbergwerf - Aug-31-2020, 10:14 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  python convert multiple files to multiple lists MCL169 6 1,566 Nov-25-2023, 05:31 AM
Last Post: Iqratech
  splitting file into multiple files by searching for string AlphaInc 2 906 Jul-01-2023, 10:35 PM
Last Post: Pedroski55
  Merging multiple csv files with same X,Y,Z in each Auz_Pete 3 1,180 Feb-21-2023, 04:21 AM
Last Post: Auz_Pete
  unittest generates multiple files for each of my test case, how do I change to 1 file zsousa 0 974 Feb-15-2023, 05:34 PM
Last Post: zsousa
  Find duplicate files in multiple directories Pavel_47 9 3,142 Dec-27-2022, 04:47 PM
Last Post: deanhystad
  Python: re.findall to find multiple instances don't work but search worked Secret 1 1,223 Aug-30-2022, 08:40 PM
Last Post: deanhystad
  Extract parts of multiple log-files and put it in a dataframe hasiro 4 2,098 Apr-27-2022, 12:44 PM
Last Post: hasiro
  Search multiple CSV files for a string or strings cubangt 7 8,062 Feb-23-2022, 12:53 AM
Last Post: Pedroski55
  Rename part of filename in multiple files atomxkai 7 7,376 Feb-18-2022, 10:03 PM
Last Post: atomxkai
  Process multiple pdf files Spartan314 1 1,324 Oct-27-2021, 10:46 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020