google-sheet2Html

/*! * * Google Sheets To HTML v0.9a * * To use, simply replace the "tq?key=" value in the * URL below with your own unique Google document ID * * The Google document's sharing must be set to public * */ google.load('visualization', '1', { packages: ['table'] }); var visualization; function drawVisualization() { var query = new google.visualization.Query('https://spreadsheets.google.com/tq?key=https://docs.google.com/spreadsheets/d/1-vUEZ9tae5C_OXzSi0dQPWwUrO3H5S-gImB5afFgqDg/edit?usp=sharing'); query.setQuery('SELECT A, B, C, D label A "Duration", B "Song", C "Requested By", D "URL"'); query.send(handleQueryResponse); } function handleQueryResponse(response) { if (response.isError()) { alert('There was a problem with your query: ' + response.getMessage() + ' ' + response.getDetailedMessage()); return; } var data = response.getDataTable(); visualization = new google.visualization.Table(document.getElementById('table')); visualization.draw(data, { legend: 'bottom' }); } google.setOnLoadCallback(drawVisualization);

Wednesday, December 7, 2016

ใช้ python ควบคุมวิทยุสื่อสาร ตอน การ import โมดูล


ผู้ที่เริ่มหัดเขียนโปรแกรม อาจจะสับสนวิธีการ เรียกใช้โมดูลในภาษา python ทำให้ไปต่อไม่ถูก ตั้งแต่ บรรทัดแรก ลองอ่านบทความนี้ดู ครับ

วิธีการ import เรียกใช้ โมดูล ในที่นี้จะยกตัว โมดูล Tkinter

มี สองวิธี คือ

วิธีที่ 1

from Tkinter import *

จะสามารถ เรียกใช้ ฟังชั่นในโมดูลได้ เลย ดังในตัวอย่างที่ ผ่านมา
window = Tk()

ลองดูรายละเอียด 

from Tkinter import *

window = Tk()
window.title("HS1ZFK")
btnTxRx = Button(window, text="Tx/Rx", bg="light blue")
btnTxRx.grid(padx=80, pady=20)
window.mainloop()

วิธีที่

ในกรณีที่ต้องใช้ โมดูล หลายๆ อันในโปรแกรมเดียวกัน อาจจะเกิดปัญหาจาก ฟังชั่นในโมดูล มีชื่อ ซ้ำกัน เพื่อแก้ปัญหาดังกล่าว จะทำการ import ด้วยวิธีนี้
Import Tkinter
เมื่อจะเรียกใช้ ฟังชั่นในโมดูล ต้อง เรียกโมดูลก่อน ตามด้วยเครื่องหมาย จุด ตามด้วยชื่อฟังชั่น
window = Tkinter.Tk()

สังเกตุ โค้ดของวิธีที่ 2

import Tkinter


window = Tkinter.Tk()
window.title("HS1ZFK")
btnTxRx = Tkinter.Button(window, text="Tx/Rx", bg="light blue")
btnTxRx.grid(padx=80, pady=20)
window.mainloop()

ซึ่งทั้งสองวิธีจะได้ ผลเหมือนกันดังในภาพ
 
 


No comments:

Post a Comment