Combining 2 scripts - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Web Scraping & Web Development (https://python-forum.io/forum-13.html) +--- Thread: Combining 2 scripts (/thread-2135.html) |
Combining 2 scripts - wpothers - Feb-21-2017 I am creating a display with my friend to display some information on a screen. He is coding the information (like a clock, and newsfeed and stuff like that) while I am displaying it. So he gives me scripts and I am combining them into one script basically. The problem is I am very new to python and cannot figure out how to add this particular script to mine. Here are the two scripts in full with mine first and the one I want to add to mine next (There are two places in the scripts which you may not have, there is the background picture I am using (0.png) and there is also supposed to be a link to a news api in the other script but the site wont let me post it. If you are running it you will have to insert the bbc news api into that place.): from tkinter import * from PIL import ImageTk, Image import os import time import requests import tkinter as tk class App(tk.Tk): def __init__(self): # call the __init__ method of Tk class to create the main window tk.Tk.__init__(self) # background image img = ImageTk.PhotoImage(Image.open("0.png")) panel = Label(self, image=img) panel.pack() # clock self.label = tk.Label(self, text="", font=('comic',50,'bold'), bg='#464545', fg='#1681BE') self.label.place(height=204, width=484, x=1384, y=824) self.update_clock() # window geometry w, h = self.winfo_screenwidth(), self.winfo_screenheight() self.geometry("%dx%d+0+0" % (w, h)) self.overrideredirect(True) self.mainloop() def update_clock(self): now = time.strftime('%H:%M:%S') self.label.configure(text=now) self.after(1000, self.update_clock) app = App() import requests import tkinter as tk response = requests.get("this is a link to the news api") data = response.json() Run = "" for item in data ['articles']: Run +=(item["description"]+ " ") root = tk.Tk() deli = 100 # milliseconds of delay per character svar = tk.StringVar() labl = tk.Label(root, textvariable=svar, height=10 ) def shif(): shif.msg = shif.msg[1:] + shif.msg[0] svar.set(shif.msg) root.after(deli, shif) shif.msg = Run shif() labl.pack() root.mainloop()I don't quite know how the class function works and I'm having trouble combining them around that. Thank you for any help and ask me anything I didn't include. RE: Combining 2 scripts - wavic - Feb-21-2017 Import is here. You can use import statement at the beginning in your script to import his one. Without the file ext.! If your friend script is information.py import information RE: Combining 2 scripts - wpothers - Feb-21-2017 No that doesn't seem to be working RE: Combining 2 scripts - wavic - Feb-21-2017 Well, the Python modules are almost just that. information.py from bs4 import BeautifulSoup import requests def get_secret(url): html = requests.get(url).content soup = BeautifulSoup(html, 'lxml') secret = soup.find_all('div', _class='kill_all_humans_plan').text return secretyour_script.py import information for p in information.get_secret('http://www.veryevilpeople.org/'): print(p)In this scenario, both scripts have to be in the same directory RE: Combining 2 scripts - buran - Feb-21-2017 @wavic, did you even look at the two scripts and that they are tkinter GUI? In addition the way they are written does not make the import relatively easy.... RE: Combining 2 scripts - wavic - Feb-21-2017 @buran, no, I didn't. I speak in common point view. I don't know Tkinter. |